komm.int_to_bits
Converts an integer, or array of integers, to their bit representations (LSB first).
Parameters:
-
input
(ArrayLike
) –An integer or an $N$-dimensional array of integers.
-
width
(int
) –The width of the bit representation.
Returns:
-
NDArray[integer]
–An $(N+1)$-dimensional array of $0$s and $1$s, where the last dimension contains the bit representation of the input, with the least significant bit (LSB) as the first element.
Examples:
>>> komm.int_to_bits(16, width=5)
array([0, 0, 0, 0, 1])
>>> komm.int_to_bits(26, width=5)
array([0, 1, 0, 1, 1])
>>> komm.int_to_bits(26, width=8)
array([0, 1, 0, 1, 1, 0, 0, 0])
>>> komm.int_to_bits([0, 1, 2, 3], width=2)
array([[0, 0],
[1, 0],
[0, 1],
[1, 1]])
>>> komm.int_to_bits([0, 1, 2, 3], width=4)
array([[0, 0, 0, 0],
[1, 0, 0, 0],
[0, 1, 0, 0],
[1, 1, 0, 0]])
>>> komm.int_to_bits([[0, 1], [2, 3]], width=2)
array([[[0, 0],
[1, 0]],
[[0, 1],
[1, 1]]])