function createCrc16
createCrc16(polynomial: number): (data: Uint8Array) => number

Creates a CRC16 function for the given polynomial.

Uses init=0xffff and xor=0xffff. With CRC16_CCITT_POLYNOMIAL this matches CRC-16/X-25; other catalogue variants (CRC-16/ARC, CRC-16/MODBUS) use different init/xor and need a custom implementation.

Examples

Example 1

import { assertEquals } from "@std/assert";
import { createCrc16, CRC16_CCITT_POLYNOMIAL } from "@hertzg/crc/crc16";

const crc16 = createCrc16(CRC16_CCITT_POLYNOMIAL);

assertEquals(crc16(new TextEncoder().encode("123456789")), 0x906e);

Parameters

polynomial: number

The CRC16 polynomial to use

Return Type

(data: Uint8Array) => number

A function that calculates CRC16 for given data

Usage

import { createCrc16 } from "mod.ts";