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