0

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()
Jan
  • 1
  • 4
  • Does [this](https://stackoverflow.com/questions/699866/python-int-to-binary-string) answer your question? Also, you should use a [context manager](https://stackoverflow.com/a/36559849/16177247), instead of `open()` and `f1.close()` – TheFungusAmongUs Jan 20 '22 at 16:03
  • Yes. It helped. Thank you. – Jan Jan 20 '22 at 17:05

0 Answers0