Code128
   HOME

TheInfoList



OR:

Code 128 is a high-density linear barcode symbology defined in ISO/IEC 15417:2007. It is used for
alphanumeric Alphanumericals or alphanumeric characters are any collection of number characters and letters in a certain language. Sometimes such characters may be mistaken one for the other. Merriam-Webster suggests that the term "alphanumeric" may often ...
or numeric-only
barcode A barcode or bar code is a method of representing data in a visual, Machine-readable data, machine-readable form. Initially, barcodes represented data by varying the widths, spacings and sizes of parallel lines. These barcodes, now commonly ref ...
s. It can encode all 128 characters of
ASCII ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable character, printable and 33 control character, control c ...
and, by use of an extension symbol (FNC4), the Latin-1 characters defined in
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 generally results in more compact barcodes compared to other methods like
Code 39 Code 39 (also known as Alpha39, Code 3 of 9, Code 3/9, Type 39, USS Code 39, or USD-3) is a variable length, discrete barcode symbology defined in ISO/IEC 16388:2023. The Code 39 specification defines 43 characters, consisting of uppercase letters ...
, especially when the texts contain mostly digits. Code 128 was developed by the Computer Identics Corporation in 1981. GS1-128 (formerly known as UCC/EAN-128) is a subset of Code 128 and is used extensively worldwide in
shipping Freight transport, also referred to as freight forwarding, is the physical process of transporting commodities and merchandise goods and cargo. The term shipping originally referred to transport by sea but in American English, it has been ...
and
packaging Packaging is the science, art and technology of enclosing or protecting products for distribution, storage, sale, and use. Packaging also refers to the process of designing, evaluating, and producing packages. Packaging can be described as a coo ...
industries as a product identification code for the container and pallet levels in the supply chain.


Specification

A Code 128 barcode has seven sections: # Quiet zone # Start symbol # Encoded data # Check symbol (mandatory) # Stop symbol # Final bar (often considered part of the stop symbol) # Quiet zone The check symbol is calculated from a
weighted sum A weight function is a mathematical device used when performing a sum, integral, or average to give some elements more "weight" or influence on the result than other elements in the same set. The result of this application of a weight function is ...
(
modulo In computing and mathematics, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another, the latter being called the '' modulus'' of the operation. Given two positive numbers and , mo ...
103) of all the symbols.


Subtypes

Code 128 includes 108 symbols: 103 data symbols, 3 start symbols, and 2 stop symbols. Each symbol consists 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 the symbols 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 The minimum width of the quiet zone to the left and right of the Code 128 is 10x, where ''x'' is the minimum width of a module. It is mandatory at the left and right side of the barcode.


Start/stop and bar widths

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 sequence of 1's is a bar and a sequence of 0's is a space. A single 1 would be the thinnest line in the bar code. Three 1's 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 special because they are always followed by a 2-unit bar, forming a 13-unit long stop pattern. Reading the stop pattern left to right is the stop symbol (followed by a 2-unit bar), and reading the stop pattern right to left is the reverse stop symbol (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's weight 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 Below may refer to: *Earth *Ground (disambiguation) *Soil *Floor * Bottom (disambiguation) *Less than *Temperatures below freezing *Hell or underworld People with the surname * Ernst von Below (1863–1955), German World War I general * Fred Belo ...
) 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: So the value 54, which equals a V, is appended, then followed by the Stop code. 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.


Using FNC4 to encode high (160–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 ISO/IEC 8859-1:1998, ''Information technology—8-bit computing, 8-bit single-byte coded graphic character (computing), character sets—Part 1: Latin alphabet No. 1'', is part of the ISO/IEC 8859 series of ASCII-based standard character enc ...
) characters in a Code 128 barcode. When a single 'FNC4' is present in a string, the following symbol is read like ASCII, but the value is incremented by +128, thus taking the higher range of the ISO-8859-1 table. If the following symbol is a 'SHIFT', then a second symbol will be used to obtain the character. If two consecutive 'FNC4' characters are used, all following data characters are extended ASCII characters until two further consecutive 'FNC4' characters are encountered or the end of the symbol is reached. If during this sequence of extended encodation a single 'FNC4' character is encountered it is used to revert to standard ASCII encodation for the next data character only. 'SHIFT' and character subset characters shall have their normal effect during such a sequence. From Code 128A you can reach Latin-1 special characters from 160 (hex A0, non breaking space) up to 223 (hex DF, ß) via FNC4. The lower case characters from 224 (hex E0, à) to 254 (hex FE, þ) are available by FNC4+SHIFT B. The characters ÷ (247, hex F7) and ÿ (255, hex FF) are not available. The feature is not available for GS1-128. Since the support of Code 128 Type B (and C) is not very common, it might be easier to use a QR Code instead for characters from the ISO-8859-1 code range.


Bar code widths

Code128 specifies a combination of 6 alternating bars and spaces (3 of each) 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 widths 111323 in the tables below. The widths value is derived by counting the length of each run of 1's then 0's in the pattern, starting from the left. There will always be 6 runs and the lengths of these 6 runs form the Widths value. For example, using the pattern 10100011000, the run lengths are 1 (digit 1), 1 (digit 0), 1 (digit 1), 3 (digit 0), 2 (digit 1), 3 (digit 0). Reporting just the lengths of each run gives 1, 1, 1, 3, 2, 3, thereby producing a widths value of 111323. The "Code A", "Code B" and "Code C" symbols cause all following symbols to be interpreted according to the corresponding subcode (i.e. 128A, 128B or 128C). 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 ISO 3166-1 numeric (or numeric-3) codes are three-digit country codes defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization (ISO), to represent countries, dependent territories, and sp ...
country code and ship-to postal code follows. Thus, the U.S. ZIP code for the
White House The White House is the official residence and workplace of the president of the United States. Located at 1600 Pennsylvania Avenue Northwest (Washington, D.C.), NW in Washington, D.C., it has served as the residence of every U.S. president ...
would generally be printed as "(421) 840 20500", but would actually be coded as " tart C NC142 18 40 20 50 ode A16 heck symbol 92
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code>" FNC2 (message append) can appear anywhere within a barcode to indicate that the barcode reader should store the current string and prepend it to the string of the next barcode that's read. It is not used by GS1-128. FNC3 (initialize) can appear anywhere within a barcode to instruct the barcode reader to initialize or reprogram itself according to the barcode string's instructions. FNC4 is used to represent an extended ASCII character set (see ). It is not used by GS1-128.


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 by Code 128 Type-C

Code set C uses one code symbol to represent two digits. Thus it may create shorter barcodes if the content consists of numbers only or if there are longer sequences of digits within the code. However, when the string contains only a few digits or is mixed with a non-digit character, 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 is 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 (
tart B A tart is a baked dish consisting of a filling over a pastry base with an open top not covered with pastry. The pastry is usually shortcrust pastry; the filling may be sweet or savoury, though modern tarts are usually fruit-based, sometimes with ...
56 16 16 57 hecksum
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code>), while using code set C for the "X00Y" would result in a code 8 symbols long (
tart B A tart is a baked dish consisting of a filling over a pastry base with an open top not covered with pastry. The pastry is usually shortcrust pastry; the filling may be sweet or savoury, though modern tarts are usually fruit-based, sometimes with ...
56
ode C An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
00
ode B An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
57 hecksum
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code>). Using code set C is only advantageous under the following conditions: 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
ode C An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
12 34 hecksum
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code> but an early switch produces ...
ode C An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
01 23 ode A4 hecksum
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code>. 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 use a different code set, but it makes no difference whether this is the first or last; 16 symbols are required in either case:
tart B A tart is a baked dish consisting of a filling over a pastry base with an open top not covered with pastry. The pastry is usually shortcrust pastry; the filling may be sweet or savoury, though modern tarts are usually fruit-based, sometimes with ...
0 9 8 x 1
ode C An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
23 45 67
ode B An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
y 2 3 hecksum
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code>, or
tart B A tart is a baked dish consisting of a filling over a pastry base with an open top not covered with pastry. The pastry is usually shortcrust pastry; the filling may be sweet or savoury, though modern tarts are usually fruit-based, sometimes with ...
0 9 8 x
ode C An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
12 34 56
ode B An ode (from ) is a type of lyric poetry, with its origins in Ancient Greece. Odes are elaborately structured poems praising or glorifying an event or individual, describing nature intellectually as well as emotionally. A classic ode is structur ...
7 y 2 3 hecksum
top Top most commonly refers to: * Top, a basic term of orientation, distinguished from bottom, front, back, and sides * Spinning top, a ubiquitous traditional toy * Top (clothing), clothing designed to be worn over the torso * Mountain top, a moun ...
/code>. Optimizing the length of the resulting barcode is important when
barcode reader A barcode reader or barcode scanner is an optical scanner that can read printed barcodes and send the data they contain to computer. Like a flatbed scanner, it consists of a light source, a lens, and a light sensor for translating optical impul ...
s 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
optimal Mathematical optimization (alternatively spelled ''optimisation'') or mathematical programming is the selection of a best element, with regard to some criteria, from some set of available alternatives. It is generally divided into two subfiel ...
encoding can be found using a dynamic programming algorithm.


References


External links


Online Code128 Barcode Generator


– A detailed list of Application Identifiers.

– Font mapping of Barcodesoft, which differs from the common ascii mapping (see http://ascii-code.com/).

– Learn the Code 128 encoding algorithm with a font-based barcode solution.
Online barcode generator
– Free online Barcode generator for the various barcode types.
Barcode types in an overview
- Common 1D & 2D barcode types in an overview
Online Barcode Generator
- Free online barcode generator, 1D and 2D.


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.

– Free OCR with Code 128 recognition.

– Free JavaScript source code implementation of Code128.

– Free Java API with implementation of Code128 and other standard barcodes.
JavaScript Code 128
– Open-source JavaScript implementation of Code128 and other linear barcodes.

Guide to converting text to Code 128 barcodes. Written for
Lazarus Lazarus may refer to: People *Lazarus (name), a surname and a given name * Lazarus of Bethany, a Biblical figure described as being raised from the dead by Jesus * Lazarus, a Biblical figure from the parable of the Rich man and Lazarus * Lazar ...
(open-source, multi-platform GUI Pascal) but of general use. {{Barcodes Barcodes cs:Čárový kód#Code 128