[英]Converting byte array into float
I have a byte array: [93, 156, 244, 63] 我有一个字节数组:[93,156,244,63]
I want to convert it to a floating point number, it should be ~9.8. 我想将其转换为浮点数,应该为〜9.8。
How exactly would I go about doing this in JS? 我将如何在JS中执行此操作? I am rusty when it comes to bitwise operations.
当涉及按位运算时,我很生疏。
Thanks in advance. 提前致谢。
edit: The array should be [92,209,28,65] 编辑:数组应为[92,209,28,65]
If it is a IEEE754 single precision floating number you might do: 如果它是IEEE754单精度浮点数,则可以执行以下操作:
new Float32Array(new Uint8Array([93, 156, 244, 63]).buffer)[0]
But it returns 1.9110218286514282
for the bytes you provided. 但是它为您提供的字节返回
1.9110218286514282
。
And you may see that 1.911...
matches those bytes: http://www.binaryconvert.com/result_float.html?decimal=049046057049049048050049056050056054053049052050056050 您可能会看到
1.911...
与这些字节匹配: http : //www.binaryconvert.com/result_float.html 1.911...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.