Skip to content

komm.int_to_bits

Converts an integer, or array of integers, to their bit representations.

Parameters:

  • input (ArrayLike)

    The input integer, or array of integers.

  • width (int)

    The width of the bit representation.

  • 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 bit representation of the input, with the bit sequences in the last axis. Has the same shape as the input, but with a new last dimension of size width appended.

Examples:

>>> komm.int_to_bits(2, width=6, bit_order="LSB-first")
array([0, 1, 0, 0, 0, 0])
>>> komm.int_to_bits(2, width=6, bit_order="MSB-first")
array([0, 0, 0, 0, 1, 0])
>>> 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=4, bit_order="MSB-first")
array([[0, 0, 0, 0],
       [0, 0, 0, 1],
       [0, 0, 1, 0],
       [0, 0, 1, 1]])