Rella
Rella

Reputation: 66945

How to turn Bytes into number (IEEE754 to number) Actionscript

How to write such C# code in Actionscript?

Console.WriteLine(BitConverter.ToDouble(new byte[8] 
            { 0x77, 0xBE, 0x9F, 0x1A, 0x2F, 0x0D, 0x4F, 0x40 }, 0));

Upvotes: 2

Views: 538

Answers (1)

Patrick
Patrick

Reputation: 15717

You can rely on the ByteArray to do the conversion for you, but beware of the order of the bytes you write.

var bytes:Array = [0x77, 0xBE, 0x9F, 0x1A, 0x2F, 0x0D, 0x4F, 0x40];
var ba:ByteArray = new ByteArray();
for (var i:int = 7;i>=0;--i) ba.writeByte(bytes[i]);
ba.position = 0;
trace(ba.readDouble());

Upvotes: 2

Related Questions