(I am working in python)
Suppose I have this list of integers
a = [170, 140, 139, 180, 225, 200]
and I want to find the raw byte representation of the ASCII character each integer is mapped to. Since these are all greater than 127, they fall in the Extended ASCII set. I was originally using the chr() method in python to get the character and then encode() to get the raw byte representation.
a_bytes = [chr(decimal).encode() for decimal in a]
Using this method, I saw that for numbers greater than 127, the corresponding ASCII character is represented by 2 bytes.
[b'\xc2\xaa', b'\xc2\x8c', b'\xc2\x8b', b'\xc2\xb4', b'\xc3\xa1', b'\xc3\x88']
But when I used the bytes() method, it appears that each character had one byte.
a_bytes2 = bytes(a)
>>> b'\xaa\x8c\x8b\xb4\xe1\xc8'
So why is it different when I use chr().encode() versus bytes()?