Function bitfrob::u32_with_region

source ·
pub const fn u32_with_region(
    low: u32,
    high: u32,
    old: u32,
    replacement: u32
) -> u32
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!(u32_with_region(0, 2, 0b11111111_u32, 0), 0b1111_1000_u32);
assert_eq!(u32_with_region(1, 3, 0b11111111_u32, 0), 0b1111_0001_u32);
assert_eq!(u32_with_region(4, 7, 0b11111111_u32, 0), 0b0000_1111_u32);