[go: up one dir, main page]

u64_with_value

Function u64_with_value 

Source
pub const fn u64_with_value(
    low: u32,
    high: u32,
    old: u64,
    replacement: u64,
) -> u64
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!(u64_with_value(0, 2, 0, 1), 1 << 0);
assert_eq!(u64_with_value(1, 3, 0, 1), 1 << 1);
assert_eq!(u64_with_value(4, 7, 0, 1), 1 << 4);