::std::conv::

Function bits_to_int

pub fn bits_to_int<#uint N>(input: [bool; N]) -> int<N>
Expand

Casts a an array of bool to a signed integer by reinterpreting its bits.

Bits are laid out from LSB to MSB, so the first element of the array corresponds to the LSB of the input number and the last element corresponds to its MSB.

Note that bits in the literal binary representation are written right-to-left, while items in the literal representation of the array are written left-to-right.

Examples

assert bits_to_int([]) == int_to_bits(0i0);
assert bits_to_int([true, true, true, false]) == 0b0111i4;
assert bits_to_int([true, true, true, true]) == -0b0001i4;