Return to the C Tips
Calculate a one byte LRC checksum character using XOR
unsigned char checksum(unsigned char *buf, int len)
{
int i;
unsigned char checksum = 0x00;
unsigned char *ptr = (unsigned char *) buf;
/* calculate the XOR value for each byte */
for (i=0; i < len; i++)
checksum = checksum ^ ptr[i];
return (unsigned char) checksum;
}
[report a broken link by clicking here]