0

I am trying to convert a mac address in hex like this: 00453645f200 to a Mac address in bytes like this: x00\x45\x36\x45\xf2\x00

But if I use binascii.unhexlify, the result is like this: b'\x00E6E\xf2\x00'. How can I get the result I want?

khelwood
  • 55,782
  • 14
  • 81
  • 108
Ti a
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 19 '22 at 13:20

1 Answers1

0

You can't. The python interpreter will re-format the byte string b'x00\x45\x36\x45\xf2\x00' to b'\x00E6E\xf2\x00' automatically:

>>> b'x00\x45\x36\x45\xf2\x00'
b'x00E6E\xf2\x00'

You can however, print the hexadecimal representation of each byte via:

address = 0x00453645f200
for byte in address.to_bytes(6, 'big'):
    print(hex(byte))
Richard Neumann
  • 2,986
  • 2
  • 25
  • 50