komm.bits_to_int
Converts a bit array to its integer representation. The last dimension of the input is split into blocks of width bits, each of which is converted to an integer.
For integers wider than $63$ bits, see from_binary.
Parameters:
-
input(ArrayLike) –The input bit array. Must be an array with elements in $\{ 0, 1 \}$ whose last dimension is a multiple of
width. -
width(int) –The number of bits per integer. Must be in $[1 : 64)$.
-
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(NDArray[integer]) –The integer representation of the input bit array. Has the same shape as the input, but with the last dimension contracted by a factor of
width.
Examples:
>>> komm.bits_to_int([0, 0, 0, 0, 1, 0], width=6)
array([16])
>>> komm.bits_to_int([0, 0, 0, 0, 1, 0], width=6, bit_order="MSB-first")
array([2])
>>> komm.bits_to_int([0, 0, 0, 0, 1, 0], width=3)
array([0, 2])
>>> komm.bits_to_int([[0, 0, 1, 1], [0, 1, 0, 1]], width=2)
array([[0, 3],
[2, 2]])