Python - Decimal to Hex, Reverse byte order, Hex to Decimal

后端 未结 5 2220
误落风尘
误落风尘 2021-01-01 06:51

I\'ve been reading up a lot on stuct.pack and hex and the like.

I am trying to convert a decimal to hexidecimal with 2-bytes. Reverse the hex bit order, then convert

5条回答
  •  再見小時候
    2021-01-01 07:03

    >>> x = 36895
    >>> ((x << 8) | (x >> 8)) & 0xFFFF
    8080
    >>> hex(x)
    '0x901f'
    >>> struct.unpack('H',x))[0]
    8080
    >>> hex(8080)
    '0x1f90'
    

提交回复
热议问题