使用JavaScript编码和解码IEEE 754浮点数 [英] Encoding and decoding IEEE 754 floats in JavaScript

查看:489
本文介绍了使用JavaScript编码和解码IEEE 754浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对IEEE 754浮点数进行编码和解码,并且使用node.js中的二进制数来对网络协议进行解析。

是否有任何现有的库可以执行此操作,还是必须阅读规范并自行实施?或者我应该写一个C模块来完成它?注意,从节点0.6开始,这个功能包含在核心库中,所以这是最好的办法。



请参阅 http://nodejs.org/docs/latest/api/buffer.html 了解详细信息。



如果您正在阅读/编写二进制数据结构,你可能会考虑使用友好的包装这个功能,使事情更容易阅读和维护。插件如下: https://github.com/dobesv/node-binstruct


I need to encode and decode IEEE 754 floats and doubles from binary in node.js to parse a network protocol.

Are there any existing libraries that do this, or do I have to read the spec and implement it myself? Or should I write a C module to do it?

解决方案

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

这篇关于使用JavaScript编码和解码IEEE 754浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆