Javascript: How to convert signed Char Array to Float (maybe using IEEE754)?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 04:17:46

问题


I struggle with the result of my nodejs-JDBC-MSSQL-Binary-ResultValue. From my database I've got this

 [-78,119,99,63] // this is an array of signed Chars

In hex, 0xB2, 0x77, 0x63, 0x3F in big endian and 0x3F6377B2 as little endian.

After conversion it has to be this:

 0.8885451555252075

But how to do convert this by using javascript or nodejs?

Kind regards

Markus


回答1:


You can use "typed arrays":

var chars = new Uint8Array([-78, 119, 99, 63])
var floats = new Float32Array(chars.buffer)
> [0.8885451555252075]


来源:https://stackoverflow.com/questions/43075424/javascript-how-to-convert-signed-char-array-to-float-maybe-using-ieee754

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!