Skip to content

komm.bits_to_int

Converts a bit array to its integer representation (LSB first).

Parameters:

  • input (ArrayLike)

    An $N$-dimensional array of $0$s and $1$s. The least significant bit (LSB) is the first element in the last dimension.

Returns:

  • int | NDArray[integer]

    An integer or an $(N-1)$-dimensional array of integers. The last dimension of the input is collapsed into an integer representation while all preceding dimensions are preserved.

Examples:

>>> komm.bits_to_int([0, 0, 0, 0, 1])
16
>>> komm.bits_to_int([0, 1, 0, 1, 1])
26
>>> komm.bits_to_int([0, 1, 0, 1, 1, 0, 0, 0])
26
>>> komm.bits_to_int([[0, 0], [1, 0], [0, 1], [1, 1]])  # Each row is independently converted to an integer
array([0, 1, 2, 3])