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?
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?
You can use int.to_bytes
and binarray.hexlify
:
import binascii
binascii.hexlify((-22951875).to_bytes(4, byteorder="big", signed=True))
# b'fea1c83d'