Function bitfrob::u16_with_value
source · pub const fn u16_with_value(
low: u32,
high: u32,
old: u16,
replacement: u16
) -> u16Expand 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
lowandhighcan’t exceed the number of bits in the type.lowmust be less thanhigh.
assert_eq!(u16_with_value(0, 2, 0, 1), 1 << 0);
assert_eq!(u16_with_value(1, 3, 0, 1), 1 << 1);
assert_eq!(u16_with_value(4, 7, 0, 1), 1 << 4);