Function bitfrob::u64_region_mask
source · pub const fn u64_region_mask(low: u32, high: u32) -> u64
Expand description
Generates a bit mask where all bits in the region are 1.
The low
and high
values form an inclusive bit range where the mask
bits are 1.
This is largely a helper function for other functions in this crate, but you can use it yourself if you think it’s useful.
Panics
low
andhigh
must be less than the number of bits in the type.low
must be less than or equal tohigh
.
assert_eq!(u64_region_mask(0, 0), 0b0000_0001_u64);
assert_eq!(u64_region_mask(0, 1), 0b0000_0011_u64);
assert_eq!(u64_region_mask(0, 2), 0b0000_0111_u64);
assert_eq!(u64_region_mask(1, 3), 0b0000_1110_u64);
assert_eq!(u64_region_mask(4, 7), 0b1111_0000_u64);
assert_eq!(u64_region_mask(4, 4), 0b0001_0000_u64);