Python - 十进制到十六进制,反向字节顺序,十六进制到十进制

Jim*_*Jim 3 python hex decimal bit

我一直在读stuct.pack和hex等等.

我试图将小数转换为2字节的十六进制.反转十六进制位顺序,然后将其转换回十进制.

我正在尝试按照这些步骤...在python中

Convert the decimal value **36895** to the equivalent 2-byte hexadecimal value:

**0x901F**
Reverse the order of the 2 hexadecimal bytes:

**0x1F90**
Convert the resulting 2-byte hexadecimal value to its decimal equivalent:

**8080**
Run Code Online (Sandbox Code Playgroud)

Mar*_*nen 7

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