Function bitfrob::u128_with_value

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

Replaces the low to high bit region of old with an input up shifted by low.

The low and high values form an inclusive bit range.

The replacement value is up shifted by low bits so that it will be based at the base of the bit region.

If the replacement exceeds the bits allowed by the region they will be truncated.

Panics

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