I have a list that looks like this:
['\x12', '\x13', '\x05', ... , '\xF2']
and I'm trying to write it to a file in binary form like this:
00010010
00010011
00000101
11110010
This is what I'm doing now:
for dataLine in readData:
print int(binascii.hexlify(dataLine), 16)
And then converting to 8 bit binary like so:
def dobin(n):
digs = []
while n > 0:
digs.append(str(n % 2))
n /= 2
for x in range(len(digs), 8):
digs.append('0')
digs.reverse()
return ''.join(digs)
Is there an easy way to convert these to binary or a better way all together?