Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.ByteAlgorithmsExtensions

ByteAlgorithmsExtensions.RoundUpToPowerOfTwo(this byte) Method

For any given number return the number if it’s a power of two, or return the next higher power of two capable of fitting in the data type.

public static byte RoundUpToPowerOfTwo(this byte number);

Parameters

number System.Byte

The number to evaluate.

Returns

System.Byte

Example

byte v = 2;
Console.WriteLine($"{v.RoundUpToPowerOfTwo()}"); // outputs: 2

v = 3;
Console.WriteLine($"{v.RoundUpToPowerOfTwo()}"); // outputs: 4