0

I have a variable b whose value is b'\xac\xed\x05sr\x00'.

How can I convert it to 'aced05737200'?

s, and r are converted to 73 and 72 respectively because their ascii code are 73 and 72.

b.decode('utf-8') gives me this error

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xac in position 0: invalid start byte

nick
  • 1,022
  • 1
  • 11
  • 24
Brian
  • 10,096
  • 18
  • 73
  • 131

1 Answers1

0

Simply use .hex()-method

>>> b = b'\xac\xed\x05sr\x00'
>>> b.hex()
'aced05737200'

to get the wanted result, because it's not a problem with decoding or encoding. Your bytestring looks ok to produce a proper string object with hexadecimal numbers.

colidyre
  • 3,401
  • 11
  • 33
  • 47