-1

I have a binary format specification. The specification lists tags/objects in hex notation like 0x1000 which in the actual file when read into bytes in python is the binary string b'\x00\x10'.

There are 100s of tags and an existing mapping file is available that maps each "hex code" to a specific tag. Hence I want to be able to do a simple look-up to get the correct tag, eg. convert the 0x1000to b'\x00\x10' (one-time precomputed value that I can then simply compare to).

So how can I do this conversion?

beginner_
  • 7,230
  • 18
  • 70
  • 127

1 Answers1

0

The referenced link partially answers the question.

 0x1000.to_bytes(2, byteorder='little')

works and yes the 0x1000 can be written exactly like that without any quotes. Eg. hex literals is the actually trick I wasn't aware of. TIL.

beginner_
  • 7,230
  • 18
  • 70
  • 127