Product Code Database
Example Keywords: - $71-140
barcode-scavenger
   » » Wiki: Code 128
Tag Wiki 'Code 128'.
Tag
Code 128 is a very high-density symbology. It is used for or numeric-only . It can encode all 128 characters of and, by use of an extension symbol (FNC4), the Latin-1 characters defined in ISO/IEC 8859-1.

GS1-128 (formerly known as UCC/EAN-128) is a subset of Code 128 and is used extensively worldwide in and industries as a product identification code for the container and pallet levels in the supply chain. The symbology was formerly defined as ISO/IEC 15417:2007.


Specification
A Code 128 barcode has six sections:

  1. Quiet zone
  2. Start symbol
  3. Encoded data
  4. Check symbol
  5. Stop symbol
  6. Final bar (often considered part of the stop symbol)
  7. Quiet zone

The check symbol is calculated from a (modulo 103) of all the symbols.


Subtypes
Code 128 includes 108 symbols: 103 data symbols, 3 start symbols, and 2 stop symbols. Each symbol consist of three black bars and three white spaces of varying widths. All widths are multiples of a basic "module". Each bar and space is 1 to 4 modules wide, and are fixed width: the sum of the widths of the three black bars and three white bars is 11 modules.

The stop pattern is composed of two overlapped symbols and has four bars. The stop pattern permits bidirectional scanning. When the stop pattern is read left-to-right (the usual case), the stop symbol (followed by a 2-module bar) is recognized. When the stop pattern is read right-to-left, the reverse stop symbol (followed by a 2-module bar) is recognized. A scanner seeing the reverse stop symbol then knows it must skip the 2-module bar and read the rest of the barcode in reverse.

Despite its name, Code 128 does not have 128 distinct symbols, so it cannot represent 128 code points directly. To represent all 128 ASCII values, it shifts among three code sets (A, B, C). Together, code sets A and B cover all 128 ASCII characters. Code set C is used to efficiently encode digit strings. The initial subset is selected by using the appropriate start symbol. Within each code set, some of the 103 data code points are reserved for shifting to one of the other two code sets. The shifts are done using code points 98 and 99 in code sets A and B, 100 in code sets A and C and 101 in code sets B and C to switch between them):

  • 128A (Code Set A)ASCII characters 00 to 95 (0–9, A–Z and control codes), special characters, and FNC 1–4
  • 128B (Code Set B)ASCII characters 32 to 127 (0–9, A–Z, a–z), special characters, and FNC 1–4
  • 128C (Code Set C)00–99 (encodes two digits with a single code point) and FNC1


Quiet zone
The minimum width of the Quiet Zone to the left and right of the 128 Bar Code is 10x, where x is the minimum width of a module. It is mandatory at the left and right side of the barcode. The quiet zone must not be less than 4 mm × 1.65 mm depending on the type of bar code. Source: Figure 5.2.1.4.41 of GS1 General Specifications


Start/stop and encoded data
Each symbol in the barcode is composed of three bars and three spaces. Each bar or space is 1, 2, 3 or 4 units wide, the sum of the widths of bars must be even (4, 6 or 8 units), the sum of the widths of the spaces must be odd (3, 5 or 7 units), and total 11 units per symbol. For instance, encoding the ASCII character "0" can be viewed as 10011101100, where a 1 is a bar and a 0 is a space. A single 1 would be the thinnest line in the bar code. Three 1s in sequence (111) indicates a bar three times as thick as a single 1 bar.

There are 108 possible 11-unit wide symbols, and the code uses all possible symbols. Two of the symbols are used for stop (end-of-barcode) indication, stop and reverse stop. The two stop symbols are merged into a 13-unit long stop pattern. Reading the stop pattern left to right is the stop pattern (followed by a 2-unit bar), and reading the stop pattern right to left is the reverse stop pattern (followed by a 2-unit bar).


Check digit calculation
The check digit is a weighted modulo-103 checksum. It is calculated by summing the start code 'value' to the products of each symbol's 'value' multiplied by its position in the barcode string. The start symbol and first encoded symbol are in position 1. The sum of the products is then reduced modulo 103. The remainder is then converted back to one of the 103 non-delimiter symbols (following the instructions given below) and appended to the barcode, immediately before the stop symbol.

For example, in the following table, the code 128 variant A checksum value is calculated for the alphanumeric string PJJ123C:

103
48
84
126
68
90
114
245
878
54

For the purpose of computing the check symbol, the shift and code-switch symbols are treated the same as any other symbol in the bar code. The checksum is computed over the symbol values, without regard for which code set is active at the time. For instance the code set C value "33" and the code set B value "A" are both considered to be a Code 128 value of 33, and the check digit is be computed based on the value of 33 times the symbol's position within the barcode.


Using FNC4 to encode high (128–255) characters
The special symbol FNC4 ("Function 4"), present only in code sets A and B, can be used to encode all the Latin-1 (ISO-8859-1) characters in a Code 128 barcode.Apparently ISO 15417 Annex F The feature is not widely supported and is not used in GS128.GS1 General Specifications (January 2006Version 7.0), section 5.3.1.1 GS1-128 Symbology Characteristics, stating, "Characters with ASCII values 128 to 255 may also be encoded in Code 128 Symbols. Characters with ASCII values 128 to 255 accessed by Function 4 Character (FNC4) are reserved for future use and are not used in GS1-128 Bar Code Symbols." When a single FNC4 is present in a string, the following symbol is converted to ASCII as usual, and then 128 is added to the ASCII value. (If the following symbol is a shift, then a second symbol will be used to obtain the character.) If two FNC4s are used consecutively then all following characters will be treated as such, up to the end of the string or another pair of FNC4s. Between the double FNC4s, a single FNC4 will be used to denote that the following character will be standard .


Bar code widths
Code128 specifies a combination of 6 bars and spaces for each symbol Thus, each symbol begins with a bar and ends with a space. In barcode fonts, the final bar is generally combined with the stop symbol to make a wider stop pattern. The following table details the widths associated with each bar and space for each symbol. The width of each bar or space may be 1, 2, 3 or 4 units (modules). Using the example above, an 'A' would be depicted with the pattern 10100011000, or as 111323 in the tables below.

+ Code 128
0spacespace0032 or 212 / 252␣ or Ô / ü11011001100212222
1!!0133!11001101100222122
2""0234"11001100110222221
3##0335#10010011000121223
4$$0436$10010001100121322
5%%0537%10001001100131222
6&&0638&10011001000122213
7''0739'10011000100122312
8((0840(10001100100132212
9))0941)11001001000221213
10**1042*11001000100221312
11++1143+11000100100231212
12,,1244,10110011100112232
13--1345-10011011100122132
14..1446.10011001110122231
15//1547/10111001100113222
16001648010011101100123122
17111749110011100110123221
18221850211001110010223211
19331951311001011100221132
20442052411001001110221231
21552153511011100100213212
22662254611001110100223112
23772355711101101110312131
24882456811101001100311222
25992557911100101100321122
26::2658:11100100110321221
27;;2759;11101100100312212
28<<2860<11100110100322112
29==2961=11100110010322211
30>>3062>11011011000212123
31??3163?11011000110212321
32@@3264@11000110110232121
33AA3365A10100011000111323
34BB3466B10001011000131123
35CC3567C10001000110131321
36DD3668D10110001000112313
37EE3769E10001101000132113
38FF3870F10001100010132311
39GG3971G11010001000211313
40HH4072H11000101000231113
41II4173I11000100010231311
42JJ4274J10110111000112133
43KK4375K10110001110112331
44LL4476L10001101110132131
45MM4577M10111011000113123
46NN4678N10111000110113321
47OO4779O10001110110133121
48PP4880P11101110110313121
49QQ4981Q11010001110211331
50RR5082R11000101110231131
51SS5183S11011101000213113
52TT5284T11011100010213311
53UU5385U11011101110213131
54VV5486V11101011000311123
55WW5587W11101000110311321
56XX5688X11100010110331121
57YY5789Y11101101000312113
58ZZ5890Z11101100010312311
59[[5991[11100011010332111
60\\6092\11101111010314111
61]]6193]11001000010221411
62^^6294^11110001010431111
63__6395_10100110000111224
64`6496`10100001100111422
65SOHa6597a10010110000121124
66STXb6698b10010000110121421
67ETXc6799c10000101100141122
68EOTd68100d10000100110141221
69ENQe69101e10110010000112214
70ACKf70102f10110000100112412
71g71103g10011010000122114
72h72104h10011000010122411
73i73105i10000110100142112
74j74106j10000110010142211
75k75107k11000010010241211
76l76108l11001010000221114
77m77109m11110111010413111
78n78110n11000010100241112
79o79111o10001111010134111
80DLEp80112p10100111100111242
81DC1q81113q10010111100121142
82DC2r82114r10010011110121241
83DC3s83115s10111100100114212
84DC4t84116t10011110100124112
85NAKu85117u10011110010124211
86SYNv86118v11110100100411212
87ETBw87119w11110010100421112
88x88120x11110010010421211
89EMy89121y11011011110212141
90SUBz90122z11011110110214121
91{91123{11110110110412121
92FS|92124|10101111000111143
93GS}93125}10100011110111341
94RS~94126~10001011110131141
95US95200 / 240È / ð10111101000114113
96FNC 3FNC 396201 / 241É / ñ10111100010114311
97FNC 2FNC 297202 / 242Ê / ò11110101000411113
98Shift BShift A98203 / 243Ë / ó11110100010411311
99Code CCode C99204 / 244Ì / ô10111011110113141
100Code BFNC 4Code B205 / 245Í / õ10111101110114131
101FNC 4Code ACode A206 / 246Î / ö11101011110311141
102FNC 1FNC 1FNC 1207 / 247Ï / ÷11110101110411131
103Start Code A208 / 248Ð / ø11010000100211412
104Start Code B209 / 249Ñ / ù11010010000211214
105Start Code C210 / 250Ò / ú11010011100211232
106Stop11000111010233111
Reverse Stop11010111000211133
Stop pattern (7 bars/spaces)211 / 251Ó / û  1100011101011 2331112

The "Code A", "Code B" and "Code C" symbols cause all future symbols to be interpreted according to the corresponding subcode. The "Shift" symbol switches a single following symbol's interpretation between subcodes A and B.

The encoded ASCII char depends on the actual used barcode-font. Especially the ASCII char of value 0 and of value 95 and above may be defined differently in the font that is installed.

The FNC x codes are used for special purposes. FNC1 at the beginning of a bar code indicates a GS1-128 bar code which begins with a 2- 3- or 4-digit application identifier assigned by the Uniform Code Council, which explains the following digits. For example, application identifier 421 indicates that an ISO 3166-1 numeric country code and ship-to postal code follows. Thus, the U.S. for the would generally be printed as "(421) 840 20500", but would actually be coded as "[Start C] [FNC1] 42 18 40 20 50 [Code A] 0 [Check symbol 92] [Stop]"

Check digit calculation for the above Zip code example:

105
102
84
54
160
100
300
707
128
1740


Availability
For the end user, Code 128 barcodes may be generated by either an outside application to create an image of the barcode, or by a font-based barcode solution. Either solution requires the use of an application or an application add in to calculate the check digit and create the barcode.


Barcode length optimization
Although code set C uses one code symbol to represent two digits, it does not always produce a more compact code than code sets A or B. Using code set C saves one symbol per two digits, but costs a mode-shift symbol to enter and exit the set. Thus, it only worth using if there are enough consecutive digits. For example, encoding the string "X00Y" with code set A or B requires 7 code symbols ([Start B] 56 16 16 57 [checksum] [Stop]), while using code set C for the "00" would result in a code 8 symbols long ([Start B] 56 [Code C] 00 [Code B] 57 [checksum] [Stop]).

Using code set C is only advantageous under the following conditions:

4+
4+
6+
either 2 or 4+ (but not 3)

At the end of a string, delaying the transition to code set C until there are an even number of digits remaining avoids an extra symbol. Consider the string "...01234": a delayed switch produces ... 0 [Code C] 12 34 [checksum] [Stop] but an early switch produces ... [Code C] 01 23 [Code A] 4 [checksum] [Stop].GS1 General Specifications, Version 13, Issue 1, Jan-2013, Section 5.4.7.7. Use of Start, Code Set, and Shift symbols to Minimize Symbol Length (Informative), pages 268 to 269. This section gives the compression strategy.

For example, given the string "098x1234567y23", savings on barcode length using code set C are achieved only if it is applied to middle part of the string. For the beginning and ending part of the string, switching to code set C is not effective. As there are an odd number of digits in the middle of the string, the odd one must be use a different code, set, but it makes no difference whether this is the first or last; 16 symbols are required in either case: [Start B] 0 9 8 x 1 [Code C] 23 45 67 [Code B] y 2 3 [checksum] [Stop], or [Start B] 0 9 8 x [Code C] 12 34 56 [Code B] 7 y 2 3 [checksum] [Stop].

Optimizing the length of the resulting barcode is important when are used which must detect the entire barcode image at once in order to read it, such as common laser scanners. The longer the barcode is, the greater distance of laser barcode reader from barcode image is needed, making reading difficult or impossible above some threshold lengths/distances.

The encoding can be found using a dynamic programming algorithm.

(2017). 9781849967204


External links
  • GS1-128 Specification – A detailed list of Application Identifiers.
  • Barcodesoft – Font mapping of Barcodesoft, which differs from the common ascii mapping (see http://ascii-code.com/).
  • The 128 code – Learn the Code 128 encoding algorithm with a font-based barcode solution.
  • Online barcode generator – Free online Barcode generator for the various barcode types.


Sample code
  • ZXing – Multiplatform open source barcode scanner / generator with versions available in Java (core project) and ports to ActionScript, C++, C#, ObjectiveC and Ruby.
  • Python Bar Code 128 – This code appears to draw boxes one pixel wide. It appears it was modified from a short line long line bar code which would have drawn lines. The "Black boxes" should be the same size as the "White Boxes".
  • GenCode128 – Free C# source code implementation of Code128. Almost all features are implemented, but is not 100% complete.
  • Barcode1DTools Ruby gem – Ruby source code for many 1D barcode symbologies including Code 128.
  • Perl barcode generation code – Perl source code for many 1D barcode symbologies including Code 128.
  • Barcode::Code128 – Free Perl barcode generation module.
  • GOCR – Free OCR with Code 128 recognition.
  • Barcode Code 128 – Free JavaScript source code implementation of Code128.
  • Barcode4J – Free Java API with implementation of Code128 and other standard barcodes.
  • JavaScript Code 128 – Open source JavaScript implementation of Code128 and other linear barcodes.

Page 1 of 1
1

Account

Social:  .. 
Content:  ..   .. 
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs
1s Time