Skip to content

Instantly share code, notes, and snippets.

@mcxiaoke
Forked from tijnkooijmans/crc16.c
Created June 12, 2021 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcxiaoke/da21d79168b8d7f933894926e85a21ae to your computer and use it in GitHub Desktop.
Save mcxiaoke/da21d79168b8d7f933894926e85a21ae to your computer and use it in GitHub Desktop.
CRC-16/CCITT-FALSE
uint16_t crc16(char* pData, int length)
{
uint8_t i;
uint16_t wCrc = 0xffff;
while (length--) {
wCrc ^= *(unsigned char *)pData++ << 8;
for (i=0; i < 8; i++)
wCrc = wCrc & 0x8000 ? (wCrc << 1) ^ 0x1021 : wCrc << 1;
}
return wCrc & 0xffff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment