Appendix E Cyclic Redundancy Check
The cyclic redundancy check (CRC) is calculated, starting with the most significant
byte.
The algorithm for the CRC used in the Interrogator is detailed here.
unsigned char generateCrc(unsigned char newByte, unsigned char newCrc)
{
int i;
unsigned char carryOld = 0;
unsigned char carryNew = 0;
for (i = 8; i > 0; i--)+
{
;
Following 3 stmnts imitate “rotate left
through carry” of data byte
carryNew = (newByte >> 7); Shift Right 7, (high bit remains)
newByte <<= 1;
Left shift by 1
newByte |= carryOld;
Or the carry bit (previous high bit) into new-
Byte low bit
;
carryOld = carryNew;
put carryNew into carryOld
;
;
Following 3 stmnts imitate “rotate left
through carry” of CRC
carryNew = (newCrc >> 7); Get high bit of CRC, put into carryNew
newCrc <<= 1;
Make room for carry bit in low order of newCRC
newCrc |= carryOld;
Or the carry bit into newCRC
carryOld = carryNew;
Save the high order bit of CRC
if (carryNew) newCrc ^= 0x85;If carryNew non-zero, XOR newCRC with 0x85
polynomial
}
return newCrc;
}
int main(void)
{
int i, j;
AI1422E Reader User Guide
TransCore Proprietary
E–84