title: as3 ByteArray to Hex (binary hex representation)
body: <p>i hope someone can help me out here i have been struggling with this for a few days now.</p>
  
  <p>i am receiving a UDP packet via AS3 UDP datagram socket in the format of a binary hex representation (which i believe to be RAW UDP data).</p>
  
  <p>when i receive the UDP packet in as3 its in the ByteArray format which i need to convert back to the original Hexadecimal formatting.</p>
  
  <p>this is how it should look:</p>
  
  <pre><code>EF BE AD DE
  22 5C 88 06
  5E 00 00 00
  7C 11 FB 44
  00 00 00 00
  00 00 00 00
  00 00 00 00
  00 00 00 00
  02 02 01 05
  91 EE FE F4
  04 00 00 00
  00 00 01 00
  11 00 00 00
  </code></pre>
  
  <p>this is my output in flash (it doesn't need the same spacing and line breaks just the same structure, from looking at it looks like its removing the zeros? i have no idea why its doing this): </p>
  
  <p>hex= efbeaddea05b9515e0007d11fb440000000000000000221595ee76f54000001011000</p>
  
  <p>here is my as3 function: </p>
  
  <pre><code>public function hex(data:ByteArray){
      var hex:String = "";
      data.position = 0;
      var len:uint = data.length;
      for (var i:uint = 0; i &lt; len; ++i){
          var byte:uint = data.readUnsignedByte();
          hex += byte.toString(16).substr(-2);
      }
      trace("hex= "+hex);
  }
  </code></pre>
  
  <p>any help would be greatly appreciated!!</p>