Source Code Example Of Calculating A Checksum - Zektor CVS4 User Manual

High definition component video switch
Hide thumbs Also See for CVS4:
Table of Contents

Advertisement

Checksums and CRC-8's (Cont'd)
For comparison, here are the same examples and their associated CRC-8 checkcodes:
LI 2,3:16
LI 3,2:114
IL 2,3:22
KJ 2,3:145

Source Code Example of Calculating a Checksum

The following is a simple "C" program that calculates the checksum of the string "TestString" and
then prints the initial string with the calculated checksum appended to it.
#include "stdio.h"
int main( void)
{
char
unsigned char
int
char
cksum = 0; // initialize checksum
// Checksum all of 'TestString[]'
index = 0;
while (TestString[index] != '\0')
cksum += TestString[index++];
// Add the checksum token character ';' to checksum
cksum += token;
// Print the results
printf( "%s%c%u", TestString, token, (unsigned char)cksum);
return (0);
}
TestString[] = "LI 2,3";
cksum;
index;
token = ';';
CVS4 Component Video Switch
2

Advertisement

Table of Contents
loading

Table of Contents