Function bitfrob::u64_with_region

source ·
pub const fn u64_with_region(
    low: u32,
    high: u32,
    old: u64,
    replacement: u64
) -> u64
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!(u64_with_region(0, 2, 0b11111111_u64, 0), 0b1111_1000_u64);
assert_eq!(u64_with_region(1, 3, 0b11111111_u64, 0), 0b1111_0001_u64);
assert_eq!(u64_with_region(4, 7, 0b11111111_u64, 0), 0b0000_1111_u64);