我需要数字实例的二进制表示。首先,我尝试了toString()
带有参数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 解释对我来说还不够。检索数字实例的IEEE表示形式有什么帮助吗?
最好的解决方案是您自己的解决方案。我想出了这个:
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));
您可以从此处检查结果,它工作正常。