Convert bytes to bits in python

后端 未结 9 1675
轮回少年
轮回少年 2020-11-30 07:18

I am working with Python3.2. I need to take a hex stream as an input and parse it at bit-level. So I used

bytes.fromhex(input_str)

to convert t

9条回答
  •  情歌与酒
    2020-11-30 08:13

    I think simplest would be use numpy here. For example you can read a file as bytes and then expand it to bits easily like this:

    Bytes = numpy.fromfile(filename, dtype = "uint8")
    Bits = numpy.unpackbits(Bytes)
    

提交回复
热议问题