Skip to content

komm.bits_to_int

Converts a bit array to its integer representation.

Parameters:

  • input (ArrayLike)

    The input bit array. Must be an array with elements in the set $\{ 0, 1 \}$, with the bit sequences in the last axis.

  • bit_order (Literal['LSB-first', 'MSB-first'])

    Bit order convention. Must be either "LSB-first" (least significant bit in the first position) or "MSB-first" (most significant bit in the first position). The default value is "LSB-first".

Returns:

  • output (int | NDArray[integer])

    The integer representation of the input bit array. Has the same shape as the input, but with the last dimension removed.

Examples:

>>> komm.bits_to_int([0, 0, 0, 0, 1, 0], bit_order="LSB-first")
16
>>> komm.bits_to_int([0, 0, 0, 0, 1, 0], bit_order="MSB-first")
2
>>> komm.bits_to_int([[0, 0], [1, 0], [0, 1], [1, 1]])
array([0, 1, 2, 3])
>>> komm.bits_to_int([[0, 0], [1, 0], [0, 1], [1, 1]], bit_order="MSB-first")
array([0, 2, 1, 3])