0

I have an info_address that I want to convert to delimited hex

info_address_original = b'002dd748'

What i want is

info_address_coded = b'\x00\x2d\xd7\x48'

I tried this solution

info_address_original = b'002dd748'
info_address_intermediary = info_address_original.decode("utf-8") # '002dd748'
info_address_coded = bytes.fromhex( info_address_intermediary )   # b'\x00-\xd7H'

and i get

info_address_coded = b'\x00-\xd7H'

What my debugger shows

How would one go about correctly turning a bytes string like that to delimited hex? It worked implicitly in Python 2 but it doesn't work the way i would want in Python 3.

hyk
  • 75
  • 6

2 Answers2

0

This is only a representation of the bytes. '-' is the same as '\x2d'.

>>> b'\x00\x2d\xd7\x48' == b'\x00-\xd7H'
True
Daniel
  • 42,087
  • 4
  • 55
  • 81
0

The default representation of a byte string is to display the character value for all ascii printable characters and the encoded \xhh representation where hh is the hexadecimal value of the byte.

That means that b'\x00\x2d\xd7\x48' and `b'\x00-\xd7H' are the exact same string containing 4 bytes.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252