| Tip: Bookmark this page with Ctrl-D (Win) or Apple-D (Mac) | Main • Products • Know How / FAQ • Store • Contact |
Barcode Symbologies
How do I calculate a Code 128 checksum?Each character of the Code 128 character set has a numeric value. To calculate the checksum the values of all characters (including the start character) are multiplied by a weight factor, then summed up. The result is integer divided by 103, the remainder is the checksum (that's a basic Modulo 103 operation).
Here is a checksum function in C:
unsigned char calculateChecksum(unsigned char *data, int len)
{
int sum = *data - 32; // prime with start character
for(int i = 1;i<len;i++)
{
sum += i * indexFromCodeword(*(data + i));
}
return sum % 103 + 32;
}
The indexFromCodeword function simply gets the numeric value of the codeword from a table. See elsewhere in the FAQ for a Code 128 bit pattern table which can be used for that.
Code 128 is an alphanumeric barcode that encodes the full ASCII set of characters. Consequently the check digit can be a number, digit or special character, like blank or TAB. Therefore the check digit is usually not printed along with the human readable portion of Code 128. Also, most barcode scanners do not not transmit the check digit with the data read.
Note: All our applications have automatic checksum calculation for Code 128.
Make sure to also see our introductory article about Code 128 and Code 128 GS1.
Software to generate Code 128
- Barcode AddIn for Microsoft Word
- Barcode AddIn for Microsoft Excel
- Barcode Plugin for Illustrator
- Barcode Plugin for Indesign
- Barcode Command Line Tool
- .NET Barcode Library & Control
- C / C++ Barcode DLL


