I'm trying to convert back and forth an ASCII string to its binary representation as follows.
s=chr(0)*15 + chr(0x01)
bst = bin(int(binascii.hexlify(s), 16))
n = int(bst, 2)
binascii.unhexlify('%x' % n)
However, I get the following error at the end which doesn't make much sense to me.
1 binascii.unhexlify('%x' % n)
TypeError: Odd-length string
What's the issue and how can I solve it ?
Using the python console:
So the error is consistent. What you have to do is padding with
'0'
to have an even number: