Appendix b – crc calculation – Impulse 463E User Manual
Page 99
Advertising
© Sealevel Systems, Inc.
- 96 -
SeaI/O User Manual
Appendix B – CRC Calculation
To further illustrate the example shown in the CRC-16 section, the algorithm for
generating the CRC-16 is shown below.
unsigned short calc_crc(int n,unsigned char *outbound_message)
{
unsigned char carry_flag;
unsigned short crc=0xFFFF;
for (int i = 0; i < n; i++)
{
crc = crc ^ outbound_message[i];
for (int j = 0; j < 8; j++)
{
carry_flag = crc & 0x01;
crc = crc >> 1;
if (carry_flag == 1)
{
crc = crc ^ 0xA001;
}
}
}
return
crc;
}
Advertising