I have a byte array and when I print it, certain bytes are shown with ascii characters.
eg. bytearray(b'hello')
I'm trying to get it to display as bytearray(b'\x68\x65\x6c\x6c\x6f')
Is there a way to print it showing each byte in hex \xNN format?
Byte array as hex string
Byte array as hex string
Last edited by mcauser on Sun Oct 01, 2017 12:31 pm, edited 1 time in total.
Re: Byte array as hex string
Code: Select all
>>> data = bytearray(b'hello')
>>> print("".join("\\x%02x" % i for i in data))
\x68\x65\x6c\x6c\x6f