static void LCPUpdateCRC(unsigned short *crc,unsigned char byte)
{
// Local variables.
char i; // loop variable
char XORFlag; // flag indicating the polynomial should be XORed
// Combine the new data byte with the current CRC.
if (crc != NULL) { // ensure the CRC is wanted
for (i=7; i >= 0; --i) { // loop through each bit in the data byte
XORFlag = (unsigned char)((*crc & 0x8000) != 0x0000);
*crc <<= 1; // shift the CRC left
*crc |= (unsigned short)((byte >> i) & 0x01);
if (XORFlag) // check for CRC overflow
*crc ^= 0x1021; // XOR with polynomial
}
}
Procedure LCPUpdateCRC(*crc.Unicode, byte.a)
Protected i.i ; loop variable
Protected XORFlag.a ; flag indicating the polynomial should be XORed
; Combine the new Data byte With the current CRC.
If *crc ; ensure the CRC is wanted
For i = 7 To 0 Step -1 ; loop through each bit in the Data byte
XORFlag = *crc\u & $8000
*crc\u << 1 ; shift the CRC left
*crc\u | ((byte >> i) & $01)
If XORFlag ; check For CRC overflow
*crc\u ! $1021 ; XOR with polynomial
EndIf
Next i
EndIf
EndProcedure
Procedure LCPUpdateCRC(*crc.Unicode, byte.a)
Protected i.i ; loop variable
Protected XORFlag.a ; flag indicating the polynomial should be XORed
; Combine the new Data byte With the current CRC.
If *crc ; ensure the CRC is wanted
For i = 7 To 0 Step -1 ; loop through each bit in the Data byte
XORFlag = *crc\u & $8000
*crc\u << 1 ; shift the CRC left
*crc\u | ((byte >> i) & $01)
If XORFlag ; check For CRC overflow
*crc\u ! $1021 ; XOR with polynomial
EndIf
Next i
EndIf
EndProcedure
The XORFlag should be at least a 2 byte type or it will always be zero and the code will not work.
Yes I just changed the XORflag to an integer and everything works fine and gives the expected results when compared with the supplied test data. So thanks again for your help.
I thought so but when I compared the results they were not the same. It seems that each equipment manufacturer has a slightly different variation on how they implement their CRCs. So now I have about 5 or 6 different CRC calculations.