import struct
def intToHex(num): # int转16进制
return hex(num)[2:].upper()
def hexToInt(hexString): # 16进制转int
return int(hexString, 16)
def floatToHex(floatValue): # float转16进制
return struct.pack('>f', floatValue).hex().upper()
def hexToFloat(hexString): # 16进制转float
return struct.unpack('>f', bytes.fromhex(hexString))[0]
def doubleToHex(doubleValue): # double转16进制
return struct.pack('>d', doubleValue).hex().upper()
def hexToDouble(hexString): # 16进制转double
return struct.unpack('>d', bytes.fromhex(hexString))[0]
if __name__ == '__main__':
print(intToHex(1000), hexToInt("3E8"))
print(floatToHex(1.0), hexToFloat("3F800000"))
print(doubleToHex(1.00), hexToDouble("3FF0000000000000"))
结果: