Jan-17-2019, 03:03 PM
I need to obtain bytes from hexadecimal digits, and it worked sometimes, I am using:
data=bytes.fromhex('018c5b') #this is just an example
Which gives me b'\x01\x8c['
I realized that some bytes are not correctly converted, like the last one (5b). According to 'https://en.wikiversity.org/wiki/Python_Concepts/Bytes_objects_and_Bytearrays' the byte 20 is interpreted as space, and I think that is what is happening to the 5b, being interpreted as [.
This is from the aforementioned page:
>>> bytes.fromhex( ' 12 20 04 20 E6 20 d5 ' )
b'\x12 \x04 \xe6 \xd5'
Notice that the 20's are ignored and turn into space, but how can I print the 20 or other bytes, like 5b?
data=bytes.fromhex('018c5b') #this is just an example
Which gives me b'\x01\x8c['
I realized that some bytes are not correctly converted, like the last one (5b). According to 'https://en.wikiversity.org/wiki/Python_Concepts/Bytes_objects_and_Bytearrays' the byte 20 is interpreted as space, and I think that is what is happening to the 5b, being interpreted as [.
This is from the aforementioned page:
>>> bytes.fromhex( ' 12 20 04 20 E6 20 d5 ' )
b'\x12 \x04 \xe6 \xd5'
Notice that the 20's are ignored and turn into space, but how can I print the 20 or other bytes, like 5b?