我需要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表示的任何帮助吗?
答案 0 :(得分: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));
您可以检查here的结果,效果很好。