1 year ago

#75690

test-img

Jan

byte to sequence of 8 bits conversion in Python

I am learning working with binary files in Python. If I read one byte at a time, how can I convert it into a sequence of 8 bits? (stored in a datatype list for example).

My objective is to work with individual bits, however I have read that in Python one can only read bytes from a binary file. So I am asking how to do the conversion.

Thank you.

Here is my code of reading a byte:

f1=open("filename.jpg","rb")

for x in f1:
    t=f1.read(1)
    

f1.close()

python

binary

0 Answers

Your Answer

Accepted video resources