Here is an efficient C code for a fast 16-bit CRC, which is appropriate for microcontrollers (it has low complexity and requires no lookup table):
uint16_t fast_crc16(uint8_t *data, size_t length)
{
uint16_t A, crc=0;
for(size_t i=0; i<length; i++)
{
A = (crc>>8)^data[i];
crc = (A<<2)^(A<<1)^A^(crc<<8);
}
return crc;
}
This CRC, generated by x^16 + x^2 + x + 1, has HD=4 and length up to 32767 bits, which are the same as those of CRC-16-ANSI (x^16 + x^15 + x^2 + 1) and CRC-16-CCITT (x^16 + x^12 + x^5 + 1).
For more details about this CRC and other fast CRCs, see G.D. Nguyen, “Fast CRCs,” IEEE Transactions on Computers, vol. 58, no. 10, pp. 1321-1331, Oct. 2009. See also arXiv:1009.5949 [cs.IT].