Created
August 16, 2016 15:22
-
-
Save krlicmuhamed/5da7103099a4fa6500811f95d6225bea to your computer and use it in GitHub Desktop.
CRC16 Calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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