Flex接收51单片机发送过来的16进制数据转换为String
发布时间:2020-12-15 03:58:20 所属栏目:百科 来源:网络整理
导读: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()) +"
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()); }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |