Given a binary compressed file with resolution, I would like to convert the sub-byte bits to their integer representations in python. By this, I mean that I need to interpret bits of n from a file as a whole.
I am currently reading a file into bitarray objects and converting subsets of objects to integers. The process works, but rather slow and cumbersome. Is there a better way to do this, perhaps with a struct module?
import bitarray bits = bitarray.bitarray() with open('/dir/to/any/file.dat','r') as f: bits.fromfile(f,2)
Outputs:
All bits: bitarray('0000100110000000') field1: 0000=0 field2: 100=4 field3: 110000000=384
source share