0

我需要 Number 实例的二进制表示。首先,我尝试toString()了带参数的 Number 类的方法2。结果是 14 位。(对于数字 9878.658456)然后,我尝试将 Number 实例添加到 ByteArray,如下所示:

    var b:ByteArray = new ByteArray();
    var n :Number = 9878.658456;
    trace(uint(n).toString(2));
    b.writeDouble(n);

然后我尝试读取 8 个字节:

    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));
    trace((b.readByte() ).toString(2));

结果真的很有趣,有一些我不知道该怎么处理的二进制值。我想我还没有理解 toString 方法,API 解释对我来说还不够。对检索 Number 实例的 IEEE 表示有任何帮助吗?

4

1 回答 1

0

最好的解决方案是您自己的解决方案。我想出了这个:

    var b:ByteArray = new ByteArray();
    var n :Number = 9878.658456;
    b.writeDouble(n);
    b.position=0;
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));
    trace((b.readByte() & 0xFF).toString(2));

你可以从这里检查结果,它工作正常。

于 2012-09-17T13:25:10.433 回答