[update]Need help with CRC16

Adapted from here: Modbus crc16 calculation function error syntax - #6 by Steve-Mcl

Function...

 function crc16(str) {
    const buf = Buffer.from(str)
    let crc = 0xFFFF;
    for (let i = 0; i < buf.length; i++) {
        crc = crc ^ buf[i];
        for (let j = 0; j < 8; j++) {
            const temp = crc & 0x01;
            crc >>= 0x01;
            if (temp == 0x01) {
                crc ^= 0xA001;
            }
        }
    }
    return crc;
}

Proof...
image

1 Like