Code 128 is a high-density linear barcode symbology defined in ISO/IEC 15417:2007.
[citation needed] It generally results in more compact barcodes compared to other methods like Code 39, especially when the texts contain mostly digits.
[2] GS1-128 (formerly known as UCC/EAN-128) is a subset of Code 128 and is used extensively worldwide in shipping and packaging industries as a product identification code for the container and pallet levels in the supply chain.
Each symbol consists of three black bars and three white spaces of varying widths.
The stop pattern is composed of two overlapped symbols and has four bars.
To represent all 128 ASCII values, it shifts among three code sets (A, B, C).
Code set C is used to efficiently encode digit strings.
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.
[3] 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.
Code128 specifies a combination of 6 alternating bars and spaces (3 of each) for each symbol.
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.
Reporting just the lengths of each run gives 1, 1, 1, 3, 2, 3, thereby producing a widths value of 111323.
The encoded ASCII char depends on the actual used barcode-font.
Thus, the U.S. ZIP code for the White House would generally be printed as "(421) 840 20500", but would actually be coded as "[Start C] [FNC1] 42 18 40 20 50 [Code A] 16 [Check symbol 92] [Stop]" 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.
Thus it may create shorter barcodes if the content consists of numbers only or if there are longer sequences of digits within the 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.
For the beginning and ending part of the string, switching to code set C is not effective.
The optimal encoding can be found using a dynamic programming algorithm.