Code 128
Encyclopedia
Code 128 is a very high-density barcode
Barcode
A barcode is an optical machine-readable representation of data, which shows data about the object to which it attaches. Originally barcodes represented data by varying the widths and spacings of parallel lines, and may be referred to as linear or 1 dimensional . Later they evolved into rectangles,...

 symbology. It is used for alphanumeric
Alphanumeric
Alphanumeric is a combination of alphabetic and numeric characters, and is used to describe the collection of Latin letters and Arabic digits or a text constructed from this collection. There are either 36 or 62 alphanumeric characters. The alphanumeric character set consists of the numbers 0 to...

 or numeric-only barcode
Barcode
A barcode is an optical machine-readable representation of data, which shows data about the object to which it attaches. Originally barcodes represented data by varying the widths and spacings of parallel lines, and may be referred to as linear or 1 dimensional . Later they evolved into rectangles,...

s. It can encode all 128 characters of ASCII
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

 and, by use of an extension character (FNC4), the Latin-1 characters defined in ISO/IEC 8859-1
ISO/IEC 8859-1
ISO/IEC 8859-1:1998, Information technology — 8-bit single-byte coded graphic character sets — Part 1: Latin alphabet No. 1, is part of the ISO/IEC 8859 series of ASCII-based standard character encodings, first edition published in 1987. It is informally referred to as Latin-1. It is generally...

. GS1-128
GS1-128
GS1-128 is an application standard of the GS1 implementation using the Code 128 barcode specification. The former correct name was UCC/EAN-128. Other no longer used names have included UCC-128 and EAN-128...

 (formerly known as UCC/EAN-128) is a subset of Code 128 and is used extensively world wide in shipping
Shipping
Shipping has multiple meanings. It can be a physical process of transporting commodities and merchandise goods and cargo, by land, air, and sea. It also can describe the movement of objects by ship.Land or "ground" shipping can be by train or by truck...

 and packaging 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 will have six sections:
  • Quiet Zone
  • Start Character
  • Encoded Data
  • Check Character
  • Stop Character
  • Quiet Zone


The check character is calculated from a weighted sum (modulo
Modular arithmetic
In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" after they reach a certain value—the modulus....

 103) of all the characters.

Subtypes

Code 128 includes 101 symbols: 103 data symbols, 3 start codes, and 1 stop code. To represent all 128 ASCII values, there are three code sets (A, B, C), which can be mixed within a single barcode (by using codes 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 each two digits with one code) and FNC1

Quiet Zone

The quiet zone should be at least ten times the width of the narrowest bar/space element. It is mandatory at the left and right side of the barcode. The quiet zone must not be less than 6.4mm wide.

Start/Stop and Encoded Data

Each character in the barcode symbol is composed of three bars and three spaces. (The stop adds an additional extra bar of length 2.) Each bar or space is 1, 2, 3 or 4 units wide, the sum of the widths of bars must be even, the sum of the widths of the spaces must be odd, and total 11 unit
Pixel
In digital imaging, a pixel, or pel, is a single point in a raster image, or the smallest addressable screen element in a display device; it is the smallest unit of picture that can be represented or controlled....

s per character. For instance, encoding the ASCII value 0 can be viewed as 10011101100, where a 1(One) is a bar and a 0 is a space. A combination which contains a single 1 would be the thinnest line in the bar code. A combination including three 1 (111) in sequence indicates a bar three times as thick as a single 1 bar. More information is available at Barcode Island.

The code uses 107 of the 108 possible patterns that fulfil the required criteria, with the pattern 211133 deliberately remaining unused. This is done to enhance omnidirectional scanning and help prevent misreads (if 211133 represented a legitimate symbol it could be mistaken for the stop code 2331112 when scanned backwards).

Check Digit Calculation

The check digit is a Modulo 103 checksum. It is calculated by summing the start code 'value' to the products of each character's 'value' multiplied by its position in the barcode string. The start character and first encoded value is in position 1. The sum of the start code value and the products is then divided by 103. The remainder of the division is the check digit's 'value' which is then converted into a character (following the instructions given below) and appended to the end of the barcode.

For example, in the following table, the code 128 variant A checksum value is calculated for the alphanumeric string PJJ123C
Weight Code Value Weight x Value
1 Start Code A 103 103
P 48 48
2 J 42 84
3 J 42 126
4 1 17 68
5 2 18 90
6 3 19 114
7 C 35 245
Sum 878
Divisor 103
Sum/Divisor 8.524
Remainder & Check Sum Value 54

Calculating Check Digit With Multiple Variants

As Code 128 allows multiple variants, as well as switching between variants within a single barcode, it is important to remember that the absolute Code 128 value of a character is completely independent of its value within a given variant. For instance the Variant C value "33" and the Variant B value "A" are both considered to be a Code 128 value of 33, and the check digit would be computed based on the value of 33 times the character's position within the barcode. A complete table of Variant B and C values, as well as algorithmic conversion between Code 128 values and ASCII values, is available here.

Conversion To Char

The final conversion is given by the following criteria: if the value to convert is less than 95 then the ASCII value is obtained by adding 32 to the check digit's value; otherwise the ASCII value is obtained adding 105 ( = 32 + 73). This is done to prevent the ASCII value falling within the unwanted range 127-199. Here are some examples:

Value = 6: 6 + 32 = 38 ('&')

> OK
Value = 95: 95 + 32 = 127

> WRONG: illegal character; 95 + 105 = 200 ('È') > OK

Bar Code Widths

Code128 specifies a combination of 6 bars and spaces for each character except the Stop character, which uses 7. Thus, each character begins with a bar and ends with a space (with the exception of the stop character, which ends in a bar). The following tables detail the widths associated with each bar and space for each character. The width of each bar or space can be 1, 2, 3 or 4 units. Using the example above, an 'A' would be depicted with the pattern 10100011000, or as 111323 in the tables below.
Code 128
Value 128A 128B 128C ASCII Code Character Bar/Space Pattern Bar/Space Weights
0 space
Space (punctuation)
In writing, a space is a blank area devoid of content, serving to separate words, letters, numbers, and punctuation. Conventions for interword and intersentence spaces vary among languages, and in some cases the spacing rules are quite complex....

space 00 0032 or 0212 Space or Ô 11011001100 212222
1 ! ! 01 33 ! 11001101100 222122
2 " " 02 34 " 11001100110 222221
3 # # 03 35 # 10010011000 121223
4 $ $ 04 36 $ 10010001100 121322
5  %  % 05 37 % 10001001100 131222
6 & & 06 38 & 10011001000 122213
7 ' ' 07 39 ' 10011000100 122312
8 ( ( 08 40 ( 10001100100 132212
9 ) ) 09 41 ) 11001001000 221213
10 * * 10 42 * 11001000100 221312
11 + + 11 43 + 11000100100 231212
12 , , 12 44 , 10110011100 112232
13 - - 13 45 - 10011011100 122132
14 . . 14 46 . 10011001110 122231
15 / / 15 47 / 10111001100 113222
16 0 0 16 48 0 10011101100 123122
17 1 1 17 49 1 10011100110 123221
18 2 2 18 50 2 11001110010 223211
19 3 3 19 51 3 11001011100 221132
20 4 4 20 52 4 11001001110 221231
21 5 5 21 53 5 11011100100 213212
22 6 6 22 54 6 11001110100 223112
23 7 7 23 55 7 11101101110 312131
24 8 8 24 56 8 11101001100 311222
25 9 9 25 57 9 11100101100 321122
26  :  : 26 58 : 11100100110 321221
27 ; ; 27 59 ; 11101100100 312212
28 < < 28 60 < 11100110100 322112
29 = = 29 61 = 11100110010 322211
30 > > 30 62 > 11011011000 212123
31  ?  ? 31 63 ? 11011000110 212321
32 @ @ 32 64 @ 11000110110 232121
33 A A 33 65 A 10100011000 111323
34 B B 34 66 B 10001011000 131123
35 C C 35 67 C 10001000110 131321
36 D D 36 68 D 10110001000 112313
37 E E 37 69 E 10001101000 132113
38 F F 38 70 F 10001100010 132311
39 G G 39 71 G 11010001000 211313
40 H H 40 72 H 11000101000 231113
41 I I 41 73 I 11000100010 231311
42 J J 42 74 J 10110111000 112133
43 K K 43 75 K 10110001110 112331
44 L L 44 76 L 10001101110 132131
45 M M 45 77 M 10111011000 113123
46 N N 46 78 N 10111000110 113321
47 O O 47 79 O 10001110110 133121
48 P P 48 80 P 11101110110 313121
49 Q Q 49 81 Q 11010001110 211331
50 R R 50 82 R 11000101110 231131
51 S S 51 83 S 11011101000 213113
52 T T 52 84 T 11011100010 213311
53 U U 53 85 U 11011101110 213131
54 V V 54 86 V 11101011000 311123
55 W W 55 87 W 11101000110 311321
56 X X 56 88 X 11100010110 331121
57 Y Y 57 89 Y 11101101000 312113
58 Z Z 58 90 Z 11101100010 312311
59 [ [ 59 91 [ 11100011010 332111
60 \ \ 60 92 \ 11101111010 314111
61 ] ] 61 93 ] 11001000010 221411
62 ^ ^ 62 94 ^ 11110001010 431111
63 _ _ 63 95 _ 10100110000 111224
64 NUL
Null character
The null character , abbreviated NUL, is a control character with the value zero.It is present in many character sets, including ISO/IEC 646 , the C0 control code, the Universal Character Set , and EBCDIC...

` 64 96 ` 10100001100 111422
65 SOH a 65 97 a 10010110000 121124
66 STX b 66 98 b 10010000110 121421
67 ETX
End-of-text character
The End Of Text character is an ASCII control character used to inform the receiving computer that the end of the data stream has been reached. This may or may not be an indication that all of the data has been received....

c 67 99 c 10000101100 141122
68 EOT
End-of-transmission character
In telecommunication, an end-of-transmission character is a transmission control character. Its intended use is to indicate the conclusion of a transmission that may have included one or more texts and any associated message headings....

d 68 100 d 10000100110 141221
69 ENQ e 69 101 e 10110010000 112214
70 ACK
Acknowledge character
In telecommunications, an acknowledge character is a transmission control character transmitted by the receiving station as an acknowledgement, i.e...

f 70 102 f 10110000100 112412
71 BEL
Bell character
A bell code is a device control code originally sent to ring a small electromechanical bell on tickers and other teleprinters and teletypewriters to alert operators at the other end of the line, often of an incoming message...

g 71 103 g 10011010000 122114
72 BS
Backspace
Backspace is the keyboard key that originally pushed the typewriter carriage one position backwards, and in modern computer displays moves the cursor one position backwards, deletes the preceding character, and shifts back the text after it by one position....

h 72 104 h 10011000010 122411
73 HT
Tab key
Tab key on a keyboard is used to advance the cursor to the next tab stop.- Origin :The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form"...

i 73 105 i 10000110100 142112
74 LF j 74 106 j 10000110010 142211
75 VT k 75 107 k 11000010010 241211
76 FF l 76 108 l 11001010000 221114
77 CR
Carriage return
Carriage return, often shortened to return, refers to a control character or mechanism used to start a new line of text.Originally, the term "carriage return" referred to a mechanism or lever on a typewriter...

m 77 109 m 11110111010 413111
78 SO n 78 110 n 11000010100 241112
79 SI o 79 111 o 10001111010 134111
80 DLE p 80 112 p 10100111100 111242
81 DC1 q 81 113 q 10010111100 121142
82 DC2 r 82 114 r 10010011110 121241
83 DC3 s 83 115 s 10111100100 114212
84 DC4 t 84 116 t 10011110100 124112
85 NAK
Negative-acknowledge character
* In telecommunications, a negative-acknowledge character is a transmission control character sent by a station as a negative response to the station with which the connection has been set up....

u 85 117 u 10011110010 124211
86 SYN v 86 118 v 11110100100 411212
87 ETB w 87 119 w 11110010100 421112
88 CAN
Cancel character
In telecommunication, the term cancel character has the following meanings:#A control character used to indicate that the data with which it is associated are in error or are to be disregarded....

x 88 120 x 11110010010 421211
89 EM y 89 121 y 11011011110 212141
90 SUB
Substitute character
A substitute character is a control character that is used in the place of a character that is recognized to be invalid or in error or that cannot be represented on a given device....

z 90 122 z 11011110110 214121
91 ESC
Escape character
In computing and telecommunication, an escape character is a character which invokes an alternative interpretation on subsequent characters in a character sequence. An escape character is a particular case of metacharacters...

{ 91 123 { 11110110110 412121
92 FS 92 124 10101111000 111143
93 GS } 93 125 } 10100011110 111341
94 RS ~ 94 126 ~ 10001011110 131141
95 US DEL
Delete key
The delete key , known less ambiguously as forward delete, performs a function when struck on a computer keyboard during text or command editing, which is to discard the character ahead of the cursor's position, moving all following characters one position "back" towards the freed letterspace. The...

95 200 È 10111101000 114113
96 FNC 3 FNC 3 96 201 É 10111100010 114311
97 FNC 2 FNC 2 97 202 Ê 11110101000 411113
98 Shift B Shift A 98 203 Ë 11110100010 411311
99 Code C Code C 99 204 Ì 10111011110 113141
100 Code B FNC4 Code B 205 Í 10111101110 114131
101 FNC 4 Code A Code A 206 Î 11101011110 311141
102 FNC 1 FNC 1 FNC 1 207 Ï 11110101110 411131
103 Start Code A --- --- 208 Ð 11010000100 211412
104 Start Code B --- --- 209 Ñ 11010010000 211214
105 Start Code C --- --- 210 Ò 11010011100 211232
106 Stop (7 bars/spaces) --- --- 211 Ó 1100011101011 2331112
--- unused to prevent misreading --- --- --- --- --- 211133


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 accoding ASCII char depends on the actual used barcode-font. Especially the ASCII char of value 0 and of value 95 and above can be defined differently in the font that is installed.

The FNCx codes are used for special purposes. FNC1 at the beginning of a bar code indicates that it 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
ISO 3166-1 numeric
ISO 3166-1 numeric codes are three-digit country codes defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization , to represent countries, dependent territories, and special areas of geographical interest...

 country code and ship-to postal code follows. For example, the U.S. ZIP code
ZIP Code
ZIP codes are a system of postal codes used by the United States Postal Service since 1963. The term ZIP, an acronym for Zone Improvement Plan, is properly written in capital letters and was chosen to suggest that the mail travels more efficiently, and therefore more quickly, when senders use the...

 for the White House
White House
The White House is the official residence and principal workplace of the president of the United States. Located at 1600 Pennsylvania Avenue NW in Washington, D.C., the house was designed by Irish-born James Hoban, and built between 1792 and 1800 of white-painted Aquia sandstone in the Neoclassical...

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 80] [Stop]"

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.
External links

Sample code

  • Python Bar Code 128 This code appears to draw boxes 1 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.
  • 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.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK