JS 串口 16进制数据累加和取低位,16进制字符串所有字节加起来,再取余
function checkEnd(str) {
let itotal = 0,
len = str.length,
num = 0;
while (num < len) {
let s = str.substring(num, num + 2);
itotal += parseInt(s, 16);
num = num + 2;
}
let mode = itotal % 256;
let shex = mode.toString(16);
let iLen = shex.length;
if (iLen < 2) {
shex = "0" + shex;
}
return shex;
}
本文介绍了一个JavaScript函数,用于计算16进制字符串中所有字节的累加和,并返回累加后的结果对256取余后的16进制字符串。该方法适用于校验和等场景。
5289

被折叠的 条评论
为什么被折叠?



