I'm attempting to create a data encoder in Python. I'm using my own unique underlying symmetric algorithm to encode a single 8-bit byte to another 8-bit byte and then decode it using the same algorithm.
I'm using Python's bytearray function to turn strings into bytes. However I'm running into this issue: The hexadecimal xAB can be represented in binary as 1010 1011. Yet when I use byte array on the string representation ("\xAB") I get:
>>> byte = bytearray("\xAB", "utf-8") >>> print(byte) bytearray(b'\xc2\xab') Clearly the string is represented in the single byte of \xAB, but why is the other byte \xC2 being prepended to the byte array? I'm using UTF-8 to encode the data since that is Python's default, but should I be using a different encoding? How can I get the bytearray to contain only the 8 bit byte needed to represent xAB?