Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.ByteAlgorithmsExtensions

ByteAlgorithmsExtensions.GetLowestBitSet(this byte) Method

Calculate the index of the lowest bit that’s been set.

public static int GetLowestBitSet(this byte number);

Parameters

number System.Byte

The number to evaluate.

Returns

System.Int32 The index of the lowest bit that’s been set; or -1 if none were set.

Example

byte v = 1;
Console.WriteLine($"{v.GetLowestBitSet()}"); // outputs: 0

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

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

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