Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 17x 9x 1x 8x 8x 53x 53x 424x 8x | export function crc16(data: Buffer, offset: number = 0): number {
if (data == null || offset < 0 || offset > data.length - 1) {
return 0;
}
let crc = 0xFFFF;
for (let i = 0; i < data.length; ++i) {
crc ^= data[offset + i] << 8;
for (let j = 0; j < 8; ++j) {
crc = (crc & 0x8000) > 0 ? (crc << 1) ^ 0x1021 : crc << 1;
}
}
return crc & 0xFFFF;
} |