The OpenD Programming Language

nLeadingBitsToCount

T
nLeadingBitsToCount
(
T
)
(
in T value
,
in T popcnt
)
if (
__traits(isUnsigned, T)
)

Examples

assert(nLeadingBitsToCount(0xF0u, 3u) == 32 - 5);
assert(nLeadingBitsToCount(0x700u, 3u) == 32 - 8);

foreach(uint i; 1 .. 32)
    assert(nLeadingBitsToCount(uint.max, i) == i);

Meta