Bit_Operations module

bit_scan_forward

procedure · 1 overloadSource

The 1-based position of the lowest set bit of input: 1 for bit 0, 4 for bit 3. Returns 0 when no bit is set.

Only the size_of(T) bytes of the value count, so a negative signed integer is scanned as its two's-complement bits and never as a sign-extended 64-bit number.

ExampleOpen in playground ↗
assert(bit_scan_forward(cast(u32) 1) == 1);
assert(bit_scan_forward(cast(u32) 0b1000) == 4);
assert(bit_scan_forward(cast(u8) 0b1010_0000) == 6);
assert(bit_scan_forward(cast(u32) 0) == 0);
bit_scan_forward :: (input: $T) -> s32

Parameters

input: $T

Returns

s32

See also