I have a file filled with binary data representing a sequence of 2 byte instructions in big endian ordering.
I need to be able to decode these instructions into their more meaningful equivalents, but I'm having trouble getting the data into a format I can work with.
I think it would be best If I turned the instructions into actual strings of 0's and 1's.
So far, I've written this:
def slurpInstructions(filename):
instructions = []
with open(filename, 'rb') as f:
while True:
try:
chunk = f.read(1)
print(struct.unpack('c', chunk))
except:
break
which prints out the bytes 1 at a time, like this:
(b'\x00',)
(b'a',)
I know the first instruction in the file is:
0000000001100001
So, it looks like it's printing out the ascii chars corresponding to the integer values of each byte, except it's just printing out the hex representation when there's no ascii char for the int value.
Where do I go from here though? I need to turn my b'a'
into '1100001'
because I actually care about the bits, not the bytes.