Flex接收51单片机发送过来的16进制数据转换为String

来源:互联网 发布:下载easyrecovery软件 编辑:程序博客网 时间:2024/06/02 04:15
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());
}
0 0
原创粉丝点击