SOURCE

function getCRC16(decimalBytes) {
    let crc = 0xFFFF;
    let tabccitt = [];
    for (let i = 0; i < 256; i++) {
        let ccitt = 0;
        let c = i << 8;
        for (let j = 0; j < 8; j++) {
            if ((ccitt ^ c) & 0x8000) {
                ccitt = (ccitt << 1) ^ 0x1021;
            } else {
                ccitt = ccitt << 1;
            }
            c = c << 1;
        }
        tabccitt.push(uint16ToHexString(ccitt));
    }
    for (let number of decimalBytes) {
        const sc = 0x00FF & number;
        const index = (0xFFFF) & ((crc >>> 8) ^ sc);
        const n = Number.parseInt(tabccitt[index], 16);
        crc = (0xFFFF) & ((0xFFFF) & (crc << 8)) ^ ((0xFFFF) & n);
    }
    return crc;
}
function uint16ToHexString(number) {
    let ret = [];
    let string = number.toString(16);
    const length = string.length;
    for (let i = length; 4 - i > 0; i++) {
        ret.push('0');
    }
    if (length <= 4) {
        ret.push(string);
    } else {
        ret.push(string.substr(-4));
    }
    return ret.join('');
}
let crc = getCRC16([0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10]);
console.log(uint16ToHexString(crc));
console 命令行工具 X clear

                    
>
console