Consider a file that contains binary data represented as bytes:
with open('foo', 'rb') as f:
bs = f.read()
print(bs)
# b'\x00\x01\x00\x01\x00\x01'...
The bytes can only have either 0 or 1 values.
What is the most performant way to take a group of 32 bit/bytes and parse them into a (32-bit) integer? The struct module is probably what I need but I couldn't find an immediate way to do this.
Alternative methods that involve casting bytes into chars and then parsing the integer from a bitstring e.g. int('01010101...', 2) don't perform as fast as I need them to for my use case.