I want to convert some input ASCII characters into bytes. Such as from 'a' to 01100001.
I have read answers like this. But sometimes it gives out 0b10000110 like 9 digits values. I am not sure if that's an error or that's the way it supposes to work.
I have made something like this:
text = list(input("text: "))
for character in text:
if character == ' ':
byt = '00000000'
else:
byt = bin(ord(character))
byt = byt.replace('b', '') #delete the 'b' in the output
if len(byt) != 8:
byt = '0' + byt
print(byt)
It worked pretty well with normal characters. But when I entered weird characters like: 'B
It outputs very strangely:
001110
00100111
0010000000
01000010
I am not very experienced with Python, so I don't know if there is a way that you can write a function or other methods to do this.
I am using Python 3.6
Many thanks