【问题标题】:Convert negative integer to two's complement supporting hex in python在python中将负整数转换为支持十六进制的二进制补码
【发布时间】:2020-05-20 16:23:51
【问题描述】:

我正在尝试对二进制补码 GPS 代码进行逆向工程,其中 GPS 代码是十六进制二进制补码的表示形式。

例如,0xFEA1C83D 是十进制的 -22951875。

使用 Python,如何将 -22951875 转换为 0xFEA1C83D?

【问题讨论】:

标签: python hex twos-complement


【解决方案1】:

您可以使用int.to_bytesbinarray.hexlify

import binascii
binascii.hexlify((-22951875).to_bytes(4, byteorder="big", signed=True))
# b'fea1c83d'

【讨论】:

  • 清晰简洁!谢谢你,iz_
猜你喜欢
  • 2014-03-01
  • 2021-05-16
  • 1970-01-01
  • 2019-04-30
  • 2021-12-03
  • 1970-01-01
  • 2014-12-25
  • 2014-04-16
  • 2011-09-03
相关资源
最近更新 更多