Skip to main content

pack_bit

Function pack_bit 

Source
unsafe fn pack_bit(src: *const u8, bit_idx: usize, out_pos: usize) -> u8
Expand description

Read the bit at bit_idx from src and return it shifted to out_pos, ready to be OR’d into an output byte accumulator.

src = 0b10100000  (bit 5 is set)
pack_bit(src, 5, 2)  →  0b00000100   (bit from position 5, placed at position 2)

§Safety

src must be valid for reads up to byte bit_idx / 8.