forked from: flash on 2010-8-1

by m0ose
♥0 | Line 39 | Modified 2010-08-02 01:15:54 | MIT License
play

ActionScript3 source code

/**
 * Copyright m0ose ( http://wonderfl.net/user/m0ose )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/gDr6
 */

// forked from clockmaker's flash on 2010-8-1
package {
    import flash.system.Capabilities;
    import flash.display.Sprite;
    import flash.text.*;
    
    public class FlashTest extends Sprite {
        
           public function gray2int ( n:String):int
        {
            return binary2int( gray2binary(n) )
        }
        public function gray2binary ( g:String):String
        {
            //this was hard, i tried the iteratiion teqnique.
            // i found this on the internet @ http://www.dspguru.com/comp.dsp/tricks/alg/grayconv.htm
            /*
            From: Jerry Avins <jya@ieee.org>
            Subject: Convering Between Binary and Gray Code
            Date: 28 Sep 2000
            Newsgroups: comp.dsp
            
            he also had
            unsigned short binaryToGray(unsigned short num)
            {
                return (num>>1) ^ num;
            }
            */
            var ga:int = binary2int( g )    
            var temp:int = ga ^ ( ga>>8);
            temp ^= (temp>>4);
            temp ^= (temp>>2);
            temp ^= (temp>>1);
            return int2binary (temp) ;
        }
        public function int2binary ( n:int):String
        {
            return n.toString(2);
        }

        public function int2hex( n:int ):String
        {
            return n.toString(16).toUpperCase();
        }
        public function binary2int ( n:String ):int
        {
            return parseInt(n, 2)    
        }

        
        public function FlashTest() {
            // write as3 code here..
            
              var tf:TextField = new TextField();
              addChild(tf);
              
              
              
              tf.text = gray2int( "100000100" ).toString();
              tf.appendText(" " + gray2int( "10111111").toString() );
              
              tf.scaleY = tf.scaleX = 4
            
        }
    }
}