Files
protocol_convert_software_BD3/test/test——double.py

22 lines
618 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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}")