I have a string I need to convert into a binary. I tried this:
bin = ''.join(format(ord(x), 'b') for x in strr)
But the result is the wrong length, because Python doesn't keep leading zeros. For instance instead of 01110100
it outputs 1110100
.
This method:
temp = '{0:08b}'.format(frame)
doesn't work with strings.
How can I convert a string to binary correctly?
EDIT:
Sample Input: 'test'
Desired Output: '1110100011001010111001101110100'