问题
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
)
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?
回答1:
This is working, just import the dart:typed_data
library:
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)
来源:https://stackoverflow.com/questions/55355482/parsing-integer-bit-patterns-as-ieee-754-floats-in-dart