JS 串口 16进制数据累加和取低位

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;
}

 

posted @ 2022-08-30 11:08  前进中的蜗牛  阅读(342)  评论(0编辑  收藏  举报