Drop-in C99 and Python 3 CRC-16/MODBUS with exact test vectors
CRC-16/MODBUS uses initial value `0xFFFF`, no final XOR (`0x0000`), and reflected polynomial `0xA001` (the bit-reversal of `0x8005`) processed LSB-first. Confusing it with CRC-16/CCITT (`0x1021`) or XMODEM produces completely incompatible checksums.
Open the code panel below the results to copy the self-contained C99 function (zero lookup-table flash overhead) or Python 3 script with an assertion against your active frame.
Formulas
Init = 0xFFFF; Poly_reflected = 0xA001; RefIn = True; RefOut = True; XorOut = 0x0000Check("123456789") = 0x4B37Wire append: buf[len] = crc & 0xFF; buf[len+1] = crc >> 8
Worked example
Running the bit-shift C99 or Python loop over `[0x01, 0x03, 0x00, 0x00, 0x00, 0x0A]` returns `0xCDC5`, appending `0xC5, 0xCD` on the wire.