I have a file with consecutive bytes I'm reading.
Most of these bytes I unpack 4 or 8 at a time using stuct.unpack into floats and integers, which works fine.
from struct import unpack
from sys import stdin
read_data = stdin.buffer.read()
integer_number = unpack("i", read_data[0:4])
double_number = unpack("d", read_data[4:12])
But one of the Bytes needs to be interpreted as 8 individual bits.
In the documentation there doesn't seem to be a way to convert a byte into something like two hex digits or eight binary.
I've also tried interpreting the byte as a string, which works with small numbers, but gives me stranger results the higher the number gets.
This question has been answered on SO for many languages but I couldn't find a Python3 solution.