Recurity.Swf.BitStream.FBtoInt32 C# (CSharp) Method

FBtoInt32() public method

public FBtoInt32 ( double source ) : Int32
source double
return System.Int32
        public Int32 FBtoInt32(double source)
        {
            //
            // The Swf FB[nBit] Story:
            //
            // FBs are documented as 16.16Bit values with variable length.
            // The actual implementation uses a signed 32Bit value first. That
            // value (decoded, in Int32) is split at the 16 Bit boundary. The lower
            // part is the fraction of 1.0, as seen from left to right, e.g. 0x8000
            // would be 0.5, 0xC000 would be 0.25 and so on.
            // See: http://de.wikipedia.org/wiki/Dualsystem (and don't use the English page)
            //
            // The following code uses a lot of local variables for debugging purposes.
            // The code may get optimized if required.
            //

            double abs = Math.Floor(source);
            double frac = source - abs;
            double frac2 = frac * (double)0xFFFF;
            double frac3 = Math.Round(frac2);
            UInt16 frac4 = (UInt16)frac3;
            Int16 major = (Int16)abs;
            Int32 final = unchecked((major << 16) | frac4);

            return final;
        }