-1

I'm trying to reverse engineer a twos complement GPS code, where the GPS code is a representation of a two's complement number in hex.

For example, 0xFEA1C83D is -22951875 in decimal.

Using Python, how can I convert -22951875 into 0xFEA1C83D?

Jon Mitten
  • 1,965
  • 4
  • 25
  • 53

1 Answers1

1

You can use int.to_bytes and binarray.hexlify:

import binascii
binascii.hexlify((-22951875).to_bytes(4, byteorder="big", signed=True))
# b'fea1c83d'
iz_
  • 15,923
  • 3
  • 25
  • 40