2

I am trying to convert an integer. E.g 3063294273, to a 64-bit big endian encoded byte representation. So for example if I have a value = 1 my output should be
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01

What would be the best approach to do this in python?

Edit: I saw the other question provided in Convert a Python int into a big-endian string of bytes. But in the other question, the author was not asking for a specific size of the output. Which is important for my problem.

JustPlayin
  • 89
  • 11

1 Answers1

1

int.to_bytes

>>> value = 1
>>> value.to_bytes(8, 'big')
b'\x00\x00\x00\x00\x00\x00\x00\x01'

(Your sample output is 128 bits, so if you meant that, use 16.)

Ry-
  • 218,210
  • 55
  • 464
  • 476