Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.UInt32AlgorithmsExtensions

UInt32AlgorithmsExtensions.IsPowerOfTwo(this uint) Method

Determines if the number is a power of two.

public static bool IsPowerOfTwo(this uint number);

Parameters

number System.UInt32

The number to evaluate.

Returns

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

Example

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