![Cincinnati Sub-Zero EZT-570S Reference Manual Download Page 9](http://html.mh-extra.com/html/cincinnati-sub-zero/ezt-570s/ezt-570s_reference-manual_2607293009.webp)
EZT-570S User Communication Reference Manual
9
Cyclical Redundancy Checksum (CRC) Algorithm
unsigned int calc_crc(unsigned char *start_of_packet, unsigned char *end_of_packet)
{
unsigned int crc;
unsigned char bit_count;
unsigned char *char_ptr;
/* Start at the beginning of the packet */
char_ptr = start_of_packet;
/* Initialize CRC */
crc = 0xFFFF;
/* Loop through the entire packet */
do{
/* Exclusive-OR the byte with the CRC */
crc ^= (unsigned int)*char_ptr;
/* Loop through all 8 data bits */
bit_count = 0;
do{
/* If the LSB is 1, shift the CRC and XOR the polynomial mask with the CRC */
if(crc & 0x0001){
crc >>= 1;
crc ^= 0xA001;
}
/* If the LSB is 0, shift the CRC only */
else{
crc >>= 1;
}
} while(bi+ < 7);
} while(c+ < end_of_packet);
return(crc);
}