Convert a bitarray to integer in Python I've been searching for methods to convert a bitarray into integer. Now I'm using this code:
def bin2int(bin_array):
    int_ = 0
    for bit in bin_array:
        int_ = (int_ &lt;&lt; 1) | bit
    return int_

where bin_array is a bitarray randomly filled.
I'm curios about other methods that you know of, like functions from bitarray or numpy...
There is a method in bitarray.util called ba2int:
from bitarray import bitarray
from bitarray.util import ba2int

ba = bitarray('1001')  # 9

i = ba2int(ba)

print(f'Value: {i} type: {type(i)}')
# Output: Value: 9 type: &lt;class 'int'&gt;

From the doc:

ba2int(bitarray, /, signed=False) -&gt; int
Convert the given bitarray into an integer. The bit-endianness of the
bitarray is respected. signed indicates whether two's complement is
used to represent the integer.