Encoding and decoding IEEE 754 floats in JavaScript

十年热恋 提交于 2019-11-30 19:13:12
Dobes Vandermeer

Note that as of node 0.6 this functionality is included in the core library, so that is the new best way to do it.

See http://nodejs.org/docs/latest/api/buffer.html for details.

If you are reading/writing binary data structures you might consider using a friendly wrapper around this functionality to make things easier to read and maintain. Plug follows: https://github.com/dobesv/node-binstruct

This is the best way to do it: http://github.com/pgriess/node-jspack (perhaps if you need to do things on node < 0.6.)

I ported a C++ (made with GNU GMP) converter with float128 support to Emscripten so that it would run in the browser: https://github.com/ysangkok/ieee-754

Emscripten produces JavaScript that will run on Node.js too. You will get the float representation as a string of bits, though, I don't know if that's what you want.

Maybe you can see if this thing does what you want: http://jsfromhell.com/classes/binary-parser

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