相关疑难解决方法(0)

浮点十六进制字符串返回浮点数

我想将浮点数更改为十六进制,将十六进制更改为浮点数.

所以我想得到第一个浮点数和浮点数的末尾相等.

这是我在Python 2.7上尝试过的; f1= first float,h= hex string ,=十六进制字符串中的f2新浮点值.

f1 = 15.3
h=f1.hex() #0x1.e99999999999ap+3
Run Code Online (Sandbox Code Playgroud)

如何将h十六进制字符串再次更改为浮点数?

我试过了

f2 = int(h,16)
f2 = float(h)
f2 = h.float()
Run Code Online (Sandbox Code Playgroud)

但这些都不起作用.

如果有帮助,我也可以使用Python 3.5.

python hex python-2.7 python-3.x

4
推荐指数
1
解决办法
1276
查看次数

Python二进制数据读取

urllib2请求接收二进制响应,如下所示:

00 00 00 01 00 04 41 4D 54 44 00 00 00 00 02 41
97 33 33 41 99 5C 29 41 90 3D 71 41 91 D7 0A 47
0F C6 14 00 00 01 16 6A E0 68 80 41 93 B4 05 41
97 1E B8 41 90 7A E1 41 96 8F 57 46 E6 2E 80 00
00 01 16 7A 53 7C 80 FF FF
Run Code Online (Sandbox Code Playgroud)

其结构是:

DATA, TYPE, DESCRIPTION

00 00 …
Run Code Online (Sandbox Code Playgroud)

python binary-data

3
推荐指数
3
解决办法
1万
查看次数

单精度大端浮点值到Python的浮点数(双精度,大端)

我需要通过串行线(RS-232)接收来自Arduino的十六进制编码单精度大端浮点值.如何将它们转换为具有双精度的大端的Python浮点数?

Arduino发送类似"8192323E"的东西,在Python中我希望有0.174387.我发现" 将十六进制转换为浮动 "但似乎所有这些都不适用于单精度浮点数.

从链接页面看,这很有希望:

from ctypes import *

def convert(s):
    i = int(s, 16)                   # convert from hex to a Python int
    cp = pointer(c_int(i))           # make this into a c integer
    fp = cast(cp, POINTER(c_float))  # cast the int pointer to a float pointer
    return fp.contents.value         # dereference the pointer, get the float
Run Code Online (Sandbox Code Playgroud)

但它仍然不适用于我的单精度浮子.

在Java(Processing)中,我已经能够做到这一点:

float decodeFloat(String inString) {
  byte [] inData = new byte[4];

  inString = inString.substring(2, 10); // discard the leading "f:"
  inData[0] = …
Run Code Online (Sandbox Code Playgroud)

python arduino

2
推荐指数
1
解决办法
2612
查看次数

如何在 Rust 中将十六进制字符串转换为浮点数?

将十六进制字符串转换为浮点数的最直接方法是什么?(不使用第 3 方板条箱)

Rust 是否提供了一些与 Python 相同的功能? struct.unpack('!f', bytes.fromhex('41973333'))


请参阅PythonJava 的此问题,提及以供参考。

rust

0
推荐指数
1
解决办法
1616
查看次数

标签 统计

python ×3

arduino ×1

binary-data ×1

hex ×1

python-2.7 ×1

python-3.x ×1

rust ×1