Bit_Operations module

popcount

procedure · 1 overloadSource

The number of bits set in value, counting only its size_of(T) bytes.

ExampleOpen in playground ↗
assert(popcount(cast(u32) 0) == 0);
assert(popcount(cast(u32) 0b1011) == 3);
assert(popcount(cast(s8) -1) == 8);
assert(popcount(cast(u64) 0xFFFF_FFFF_FFFF_FFFF) == 64);
popcount :: (value: $T) -> s32

Parameters

value: $T

Returns

s32

See also