Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.Int64AlgorithmsExtensions

Int64AlgorithmsExtensions.IsPowerOfTwo(this long) Method

Determines if the number is a power of two.

public static bool IsPowerOfTwo(this long number);

Parameters

number System.Int64

The number to evaluate.

Returns

System.Boolean true if number == 2^n; where n is an integer.

Example

long v = 1;
if (v.IsPowerOfTwo()) Console.WriteLine($"{v} is a power of two!"); // outputs: 1 is a power of two!

v = 2;
if (v.IsPowerOfTwo()) Console.WriteLine($"{v} is a power of two!"); // outputs: 2 is a power of two!

v = 3;
if (v.IsPowerOfTwo()) Console.WriteLine($"{v} is a power of two!"); // does not output anything.

v = 4;
if (v.IsPowerOfTwo()) Console.WriteLine($"{v} is a power of two!"); // outputs: 4 is a power of two!