Function bitfrob::u128_replicate_bits
source · [−]Expand description
Replicates the low count
bits across the entire value.
If higher bits are set in the input it will not affect the output.
This is a form of “sample depth scaling”. If your source data’s bit
depth is less than the full range of a uX
value (eg, only 5 bits out
of a u8
), this function can scale up the sample into the integer’s
full range.
Panics
count
can’t exceed the number of bits in the type.count
can’t be 0.
assert_eq!(u8_replicate_bits(5, 0b0001_0111_u8), 0b1011_1101_u8);
assert_eq!(u16_replicate_bits(5, 0b0001_0111_u16), 0b1011_1101_1110_1111_u16);
assert_eq!(u32_replicate_bits(5, 0b0001_0111_u32), 0xBDEF_7BDE_u32);
assert_eq!(u64_replicate_bits(5, 0b0001_0111_u64), 0xBDEF_7BDE_F7BD_EF7B_u64);
assert_eq!(u128_replicate_bits(5, 0b0001_0111_u128), 0xBDEF_7BDE_F7BD_EF7B_DEF7_BDEF_7BDE_F7BD_u128);