I have this byte variable
testByte = b"\x02\x00\x30\x03\x35"
I would like to print it out
I've tried:
listTestByte = list(testByte)
However, I'm getting
[2, 0, 48, 3, 35]
I'm expecting it to be:
[2, 0, 30, 3, 35]
What you have are hexadecimal values. So what you're getting is what you should be getting. (Except that you should be getting [2, 0, 48, 3, 53] and not [2, 0, 48, 3, 35].)
If you want the list to have what you have in hexadecimal you can try converting it back to hexadecimal.
testByte = b"\x02\x00\x30\x03\x35"
listTestByte = list(testByte)
print(listTestByte) # [2, 0, 48, 3, 53]
listTestByteAsHex = [int(hex(x).split('x')[-1]) for x in listTestByte]
print(listTestByteAsHex) # [2, 0, 30, 3, 35]
Or use string operations, to split at '\x' depending on your purpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With