//unicode为1个接收数据,串口收到的字符编码放在该数组中
function UnicodeToUtf8(unicode) {
var uchar;
var utf8str = "";
var i;
for(i=0; i<unicode.length;i+=2){
uchar = (unicode[i]<<8) | unicode[i+1]; //UNICODE为2字节编码,一次读入2个字节
utf8str = utf8str + String.fromCharCode(uchar); //使用String.fromCharCode强制转换
}
return utf8str;
}
function Utf8ToUnicode(strUtf8) {
var i,j;
var uCode;
var temp = new Array();
for(i=0,j=0; i<strUtf8.length; i++){
uCode = strUtf8.charCodeAt(i);
if(uCode<0x100){ //ASCII字符
temp[j++] = 0x00;
temp[j++] = uCode;
}else if(uCode<0x10000){
temp[j++] = (uCode>>8)&0xff;
temp[j++] = uCode&0xff;
}else if(uCode<0x1000000){
temp[j++] = (uCode>>16)&0xff;
temp[j++] = (uCode>>8)&0xff;
temp[j++] = uCode&0xff;
}else if(uCode<0x100000000){
temp[j++] = (uCode>>24)&0xff;
temp[j++] = (uCode>>16)&0xff;
temp[j++] = (uCode>>8)&0xff;
temp[j++] = uCode&0xff;
}else{
break;
}
}
temp.length = j;
return temp;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有