Actionscript 3 - Bits of Number in Flash

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

In flash, performing bitwise operations on Number always strips away the floating part.

  Is there a way, in flash, to get the bit representation of a Number   ?  

I have tried googling but either I couldn t phrase it well enough, or it isn t that easy to find.

  Edit, to clear something up:    I specifically   Number  , that is the class which represents   Floating Point Number   in Flash, not number in general. I suppose I could have wrote   Is there a way, in flash, to get the bit represebtation of a floating point number  ?

Answers

the only way that I can think of off the top of my head is to use a ByteArray

Something like this:

        var x:Number = 1.532;
        var ba:ByteArray = new ByteArray();
        ba.writeDouble(x);
        ba.position = 0;

        var high32bits:uint = ba.readUnsignedInt();
        var low32bits:uint = ba.readUnsignedInt();

        trace(high32bits.toString(16));  // 3ff88312
        trace(low32bits.toString(16));   // 6e978d50

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/7918037/bits-of-number-in-flash

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils