INS401 User’s Manual
_____________________________________________________________________________________
Doc# 7430-3305-08
Page 37
Appendix A: 16-bit CRC Implementation Sample Code
The following is the 16-bit CRC sample code used in most of the code development.
uint16_t CalculateCRC (uint8_t *buf, uint16_t length)
{
uint16_t crc = 0x1D0F;
for (int i=0; i < length; i++) {
crc ^= buf[i] << 8;
for (int j=0; j<8; j++) {
if (crc & 0x8000) {
crc = (crc << 1) ^ 0x1021;
}
else {
crc = crc << 1;
}
}
}
return ((crc << 8) & 0xFF00) | ((crc >> 8) & 0xFF);
}