Skip to main content

bits_to_index

Function bits_to_index 

Source
pub fn bits_to_index(bits: &[u8]) -> usize
Expand description

The index $i = \sum_{k} b_{k} 2^{n-1-k}$ of the bits $b_{0} \dots b_{n-1}$, the most significant first (only the lowest bit of every value is read).

§Examples

use comnum_math::bits_to_index;
assert_eq!(bits_to_index(&[1, 1, 0]), 6);
assert_eq!(bits_to_index(&[]), 0);