home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Darbas / kidoz_v1.air / kidoz.swf / scripts / mx / utils / HexDecoder.as < prev    next >
Encoding:
Text File  |  2009-05-06  |  1.6 KB  |  72 lines

  1. package mx.utils
  2. {
  3.    import flash.utils.ByteArray;
  4.    
  5.    public class HexDecoder
  6.    {
  7.       private var _output:ByteArray;
  8.       
  9.       private var _work:Array = [0,0];
  10.       
  11.       public function HexDecoder()
  12.       {
  13.          super();
  14.          _output = new ByteArray();
  15.       }
  16.       
  17.       public function flush() : ByteArray
  18.       {
  19.          return drain();
  20.       }
  21.       
  22.       public function drain() : ByteArray
  23.       {
  24.          var _loc1_:ByteArray = _output;
  25.          _output = new ByteArray();
  26.          _loc1_.position = 0;
  27.          return _loc1_;
  28.       }
  29.       
  30.       public function digit(param1:String) : int
  31.       {
  32.          switch(param1)
  33.          {
  34.             case "A":
  35.             case "a":
  36.                return 10;
  37.             case "B":
  38.             case "b":
  39.                return 11;
  40.             case "C":
  41.             case "c":
  42.                return 12;
  43.             case "D":
  44.             case "d":
  45.                return 13;
  46.             case "E":
  47.             case "e":
  48.                return 14;
  49.             case "F":
  50.             case "f":
  51.                return 15;
  52.             default:
  53.                return new Number(param1);
  54.          }
  55.       }
  56.       
  57.       public function decode(param1:String) : void
  58.       {
  59.          var _loc2_:int = 0;
  60.          while(_loc2_ < param1.length)
  61.          {
  62.             _work[0] = digit(param1.charAt(_loc2_));
  63.             _loc2_++;
  64.             _work[1] = digit(param1.charAt(_loc2_));
  65.             _output.writeByte((_work[0] << 4 | _work[1]) & 0xFF);
  66.             _loc2_++;
  67.          }
  68.       }
  69.    }
  70. }
  71.  
  72.