Sample CCITT CRC Code
// Update the CRC for transmitted and received data using
// the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1).
unsigned char ser_data;
static unsigned int crc;
crc = (unsigned char)(crc >> 8) | (crc << 8);
crc ^= ser_data;
crc ^= (unsigned char)(crc & 0xff) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xff) << 4) << 1;
Note: It is best not to alter this code. For example, (crc<<8)<<4 does not generate the same code as crc<<12. Although the result of the computation is the same, the latter generates much more code and executes slower.
Copyright © 1995-1999. Eagle Air Australia Pty.Ltd. All Rights Reserved.