Jcd.BitManipulation

A bit manipulation readability enhancement library.

Jcd.BitManipulation

Jcd.BitManipulation.Algorithms.Int16AlgorithmsExtensions

Int16AlgorithmsExtensions.CountLeadingZeros(this short) Method

Computes the number of sequentially zeroed bits occupying the most significant bit positions.

public static int CountLeadingZeros(this short number);

Parameters

number System.Int16

The number to evaluate.

Returns

System.Int32 The count of sequentially zeroed bits occupying the most significant bit positions.

Example

short v = 0x7FFF;
Console.WriteLine($"{v.CountLeadingZeros()}"); // outputs: 1

v = 0x3FFF;
Console.WriteLine($"{v.CountLeadingZeros()}"); // outputs: 2

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