首次提交完整的python工程代码
This commit is contained in:
22
test/test——double.py
Normal file
22
test/test——double.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import struct
|
||||
|
||||
def hex_double_to_decimal(hex_str):
|
||||
# 1. 将16进制字符串转为字节流(8字节,对应double)
|
||||
byte_data = bytes.fromhex(hex_str)
|
||||
|
||||
# 2. 使用struct解包为双精度浮点数(大端模式)
|
||||
# >d 表示大端模式、double类型
|
||||
decimal_value = struct.unpack('>d', byte_data)[0]
|
||||
|
||||
return decimal_value
|
||||
|
||||
# 输入你提供的16进制double数据
|
||||
#hex_input = "4071f0f0a49d7f87"
|
||||
hex_input = "40523c3d6d8b0464"
|
||||
|
||||
# 转换
|
||||
result = hex_double_to_decimal(hex_input)
|
||||
|
||||
# 输出结果
|
||||
print(f"十六进制double: {hex_input}")
|
||||
print(f"转换后的十进制: {result}")
|
||||
Reference in New Issue
Block a user