Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.SByteAlgorithmsExtensions

SByteAlgorithmsExtensions.IsPowerOfTwo(this sbyte) Method

Determines if the number is a power of two.

public static bool IsPowerOfTwo(this sbyte number);

Parameters

number System.SByte

The number to evaluate.

Returns

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

Example

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