(input: $T) -> T
Reverses the byte order of input and returns the result; input is untouched.
#import "Bit_Operations";
Byte swapping, bit scans and population count for integers of any size.
Reverses the byte order of input and returns the result; input is untouched.
Reverses the byte order of input where it is stored, the in-place form of byte_swap.
value: u32 = 0xAABBCCDD;
byte_swap_in_place(*value);
assert(value == 0xDDCCBBAA);↗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.
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);↗The 1-based position of the highest set bit of input, which is also the number of bits needed to hold it (so floor(log2) plus one). Returns 0 when no bit is set.
assert(bit_scan_reverse(cast(u32) 1) == 1);
assert(bit_scan_reverse(cast(u32) 0b1000) == 4);
assert(bit_scan_reverse(cast(u64) 0xFFFF_FFFF_FFFF_FFFF) == 64);
assert(bit_scan_reverse(cast(s16) -1) == 16);
assert(bit_scan_reverse(cast(u32) 0) == 0);↗The number of bits set in value, counting only its size_of(T) bytes.