本文介绍了在dart中浮动IEEE 754时解析整数位模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过接口(蓝牙,列表)获取4个字节的数据.数据表示IEEE 754浮点数(例如0x3fd0a3d7
,大约表示1.63
作为二进制32 float
)
I am getting 4 bytes of data through an interface(Bluetooth, List). The data is representing IEEE 754 float (e.g. 0x3fd0a3d7
, which represents approximately 1.63
as a binary32 float
)
在dart lang中是否有一种方法可以将其转换/键入双精度浮点数然后加倍? Java中的intBitsToFloat
之类的东西.找不到任何东西.还是我只需要自己编写IEEE 754解析文件?
Is there a way in dart lang to convert / type-pun this to float and then double? Something like intBitsToFloat
in Java. Couldn't find anything. Or do I just have to write the IEEE 754 parsing myself?
推荐答案
这有效,只需导入dart:typed_data
库:
var bdata = ByteData(4);
bdata.setInt32(0, 0x3fd0a3d7);
print(bdata.getFloat32(0)); //Prints: 1.6299999952316284
(我不确定这是最可靠的方法)
(I'm not sure this is the most reliable way)
这篇关于在dart中浮动IEEE 754时解析整数位模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!