Skip to main content

index_to_bits

Function index_to_bits 

Source
pub fn index_to_bits(index: usize, n_bits: usize) -> impl Iterator<Item = u8>
Expand description

The n_bits bits of index, the most significant first (the bits above $2^{n}$ are dropped).

§Examples

use comnum_math::index_to_bits;
assert_eq!(index_to_bits(6, 3).collect::<Vec<u8>>(), [1, 1, 0]);
assert_eq!(index_to_bits(6, 2).collect::<Vec<u8>>(), [1, 0]);