function crc16_checkout(puchMsg, usDataLen) { let crc_reg=0xFFFF; let check; for(let i =0; i>8) ^ puchMsg.charCodeAt(i); for(let j =0; j<8; j++){ check = crc_reg & 0x0001; crc_reg >>= 1; if(check == 0x0001){ crc_reg ^= 0xA001; } } } //return crc_reg.toString(16).toUpperCase(); return padLeft(crc_reg.toString(16).toUpperCase(),4,'0'); } function padLeft(s, w, pc) { if (pc == undefined) { pc = '0'; } for (var i = 0, c = w - s.length; i < c; i++) { s = pc + s; } return s; }; // let b = 'QN=20160801085857223;ST=32;CN=1062;PW=100000;MN=010000A8900016F000169DC0;Flag=5;CP=&&RtdInterval=30&&'; // let a = crc16_checkout(b, b.length); // console.log(a.toString(16).toUpperCase()); module.exports = crc16_checkout;