Skip to content

komm.from_binary

Converts a bit sequence to a single integer. Unlike bits_to_int, it works with Python integers of arbitrary size.

Parameters:

  • bits (Iterable[int])

    The input bit sequence. Must be an iterable with elements in $\{ 0, 1 \}$.

  • 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:

  • integer (int)

    The integer represented by the input bit sequence.

Examples:

>>> komm.from_binary([0, 0, 0, 0, 1, 0])
16
>>> komm.from_binary([0, 0, 0, 0, 1, 0], bit_order="MSB-first")
2
>>> komm.from_binary([0] * 100 + [1])
1267650600228229401496703205376