有没有办法看到了一些在它的64位浮点IEEE754重新presentation [英] Is there any way to see a number in it's 64 bit float IEEE754 representation
问题描述
的Javascript存储所有数字作为双precision 64位格式的IEEE根据规范:
Javascript stores all numbers as double-precision 64-bit format IEEE 754 values according to the spec:
号码类型正好有18437736874454810627(即2 64 -2 53 +3)
值,再presenting的双precision 64位格式的IEEE 754
值作为IEEE标准指定二进制浮点
算术
The Number type has exactly 18437736874454810627 (that is, 264−253+3) values, representing the double-precision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic
有没有办法看到这种形式在Javascript多少?
Is there any way to see the number in this form in Javascript?
推荐答案
您可以使用类型数组来检查数字的原始字节。用一个元素创建一个 Float64Array
,然后创建一个 Uint8Array
用相同的缓冲。然后,您可以float数组的第一个元素设置为你的电话号码,并通过 Uint8Array
检查字节。你必须做一些移动和各个部分的数量当然相结合,但它并不难。
You can use typed arrays to examine the raw bytes of a number. Create a Float64Array
with one element, and then create a Uint8Array
with the same buffer. You can then set the first element of the float array to your number, and examine the bytes via the Uint8Array
. You'll have to do some shifting and combining for the various pieces of the number of course, but it's not hard.
有没有内置的设施,不喜欢的东西提取指数。
There are no built-in facilities to do things like extract the exponent.
这篇关于有没有办法看到了一些在它的64位浮点IEEE754重新presentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!