Function bitfrob::u128_with_region

source ·
pub const fn u128_with_region(
    low: u32,
    high: u32,
    old: u128,
    replacement: u128
) -> u128
Expand description

Replaces the low to high bit region of old.

The low and high values form an inclusive bit range.

Bits in replacement outside of the region have no effect.

Panics

  • low and high can’t exceed the number of bits in the type.
  • low must be less than high.
assert_eq!(u128_with_region(0, 2, 0b11111111_u128, 0), 0b1111_1000_u128);
assert_eq!(u128_with_region(1, 3, 0b11111111_u128, 0), 0b1111_0001_u128);
assert_eq!(u128_with_region(4, 7, 0b11111111_u128, 0), 0b0000_1111_u128);