Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.Int16AlgorithmsExtensions

Int16AlgorithmsExtensions.IsPowerOfTwo(this short) Method

Determines if the number is a power of two.

public static bool IsPowerOfTwo(this short number);

Parameters

number System.Int16

The number to evaluate.

Returns

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

Example

short 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!