private static function toHex(bytes:ByteArray):String{
var pos:int =bytes.position;
bytes.position=0;
var result:String="";
while(bytes.bytesAvailable>=8){
result+=toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte())
+""+toHexNum(bytes.readUnsignedByte());
}
while(bytes.bytesAvailable>1){
result+=toHexNum(bytes.readUnsignedByte())+"";
}
if(bytes.bytesAvailable){
result+=toHexNum(bytes.readUnsignedByte());
}
bytes.position=pos;
return result;
}
private static function toHexNum(n:uint):String{
//return 0<0xF?" "+n.toString(16):n.toString(16);
return String.fromCharCode(n.toString());
}