Free Barcode Fonts @ dobsonsw.com
The following table and pseudo code is illustrated based on the free Code 128 Font found at Free Barcode Fonts. While the check digit calculation is the same with all Code 128 barcodes the location of characters within the fonts differ. There is some sample code available here.
The following table illustrates the Code 128 Value, the value of Variant B and C, and the ASCII location of the character within my Code 128 font set found at Free Barcode Fonts . If you are dealing with Unicode you will need to make the conversion between unicode and the ASCII value.
When dealing with Code 128 it is always advisable to think of a character as the Code 128 Value rather than the actual character. For instance, don't think of a capital A as a capital A. It's much easier to think of it as a Variant B code 33.
between ASCII and Code 128
1) If the ASCII value is 128 then the Code 128 Value equals 0
2) If the ASCII value is between 33 and 126 inclusive than the Code 128 Value equals the ASCII value - 32.
3) If the ASCII value is greater than 126, but not 128, then the Code 128 value equals the ASCII value - 50.
Converting Variant C to ASCII is a bit different. Outside of the special characters, the Code 128 value and the Variant C value is the same. For instance, Variant C '25' equals Code 128 25. This makes the conversion quite easy when dealing with a two character string. The code 128 value is already encoded in the string itself.
Check Digit Calculation:
Basic calculation of the Code 128 check digit is pretty easy. For expedience I will use straight variant B. However, you should be aware that code 128 allows multiple variant encoding in a single barcode. You can encode variant A, variant B, and variant C in a single barcode to take up less space.
To begin encoding you will keep a running total of the checksum of each character. The checksum is weighted based on the location of each particular character. For instance, the first character is weighted by 1. The second by 2, etc, etc, etc. To start, lets assume that we are encoding the value 'Code 128' as a barcode in variant B. The structure and checksum is as follows:
As you can see calculation of the weighted values is quite easily accomplished. To calculate the actual check digit one needs to add the values together and apply modulos 103 to the sum of the weighted values. In the above case the total checksum value is 104 + 35 + 94 + 108 + 148 + 85 + 108 + 168 = 850. 850 MOD 103 = 26. Therefore, the check digit for this barcode would be code 26 of the Code 128 set, which in ASCII terms would be ASCII 58, or the character ':'
To complete the barcode we simply add the check digit and the stop character located at ASCII 156, Code 128 value 106, to result in:
[START B] C O D E 1 2 8 : [STOP]
Code 128 Structure:
As you can see in the example above Code 128 is structured by a start character, indicating the starting variant, the data itself, followed by the check digit, and ultimately ending up with the stop character:
[START VARIANT][DATA CHARACTERS][CHECK DIGIT][STOP]
for code 128? This should get you on your way. It's not as confusing as
it looks and remember, the Code128
DLL is available to make life much easier.
| ||Copyright 2008-2011 Brian Dobson .All Rights Reserved|