Skip to content

Instantly share code, notes, and snippets.

@krlicmuhamed
Created August 16, 2016 15:22
Show Gist options
  • Save krlicmuhamed/5da7103099a4fa6500811f95d6225bea to your computer and use it in GitHub Desktop.
Save krlicmuhamed/5da7103099a4fa6500811f95d6225bea to your computer and use it in GitHub Desktop.
CRC16 Calculation
unsigned short crc_16_rec(unsigned char * pucData, unsigned short ucLen) {
//--------------------------------------------------------------------
unsigned int i;
unsigned char ucBit, ucCarry;
//--------------------------------------------------------------------
unsigned short usPoly = 0x8408; //reversed 0x1021
unsigned short usCRC = 0;
//--------------------------------------------------------------------
for (i = 0; i < ucLen; i++) {
usCRC ^= pucData[i];
for (ucBit = 0; ucBit < 8; ucBit++) {
ucCarry = usCRC & 1;
usCRC >>= 1;
if (ucCarry) {
usCRC ^= usPoly;
}
}
}
return usCRC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment