Code-128 and GS1-128 / EAN-128 / UCC-128

<< Click to Display Table of Contents >>

Navigation:  Programming Techniques > Barcodes (1D) >

Code-128 and GS1-128 / EAN-128 / UCC-128

Previous pageReturn to chapter overviewNext page

Code-128

EAN-128

ProgrammersManual_img16

ProgrammersManual_img17

BCT_CODE128

BCT_EAN128

 

Field of Application

Code-128 is a universal barcode with many applications in the industry.

GS1-128 / EAN-128 / UCC-128 are a variation of the Code-128, with a special control code (FNC1) after the startcode that identifies the barcode uniquely worldwide. To use GS1-128, EAN-128 / UCC-128 use the code type BCT_EAN128. Please note that no FNC1 control code is inserted automatically when using BCT_EAN128 (neither after the startcode). You need to insert the FNC1 control code yourself according to your requirements, please see below on how to insert control codes.

 

Charset / Number of Characters

The charset comprises all 127 ASCII characters. The number of characters is not limited.

 

Checkdigit

The use of a checkdigit is required. The barcode library can generate it automatically.

 

Characteristics

The length of the code is variable, but the maximum width of the barcode should not exceed 165mm. A maximum of 48 characters is allowed (including GS1-128 Application Identifiers and FNC codes).

 

Internal Character Representation

The Code 128 represents characters in three different character sets called A, B and C.

A: ASCII 0-96 : control characters (TAB, CR/LF, etc.), special characters and upper-case letters

B: ASCII 32-127 : special characters, upper-case and lower-case letters, but no control characters

C: Digits 0..9 : encoded in pairs

The barcode library switches between the character sets (A/B/C) automatically, in order to optimize the length of the barcode to the shortest possible representation. Normally, you do not need to switch between character sets yourself.

The character set C represents two consecutive digits at a time as a single character. This creates very compact code. The number of consecutive digits should be even for best optimization. Otherwise the barcode library needs to insert a control code to switch to another character set. Therefore a code with an even number of digits (e.g. "0000") can be represented more efficient than a code with an odd number of digits (e.g. "000").

If required, the character set can be switched within the code by inserting special control codes accordingly (see below). The switch may happen for a single character or for the rest of the code.

 

Reflections Regarding the Code Width

Because the width of the Code 128 depends on the number of used characters, your application must reserve enough space.

If no control characters with ASCII values < 32 (Tabs, Linefeed, ...) are used, the code will never become wider than a code which consists of letters only.

If control characters are used, in the worst case the code will be made up of alternating control characters and lower-case letters.

 

Inserting FNC1 - FNC4 Control Codes

The FNC control codes can be inserted by using <FNC1>, <FNC2>, <FNC3> or <FNC4> within the barcode text, or one of the following special characters:

Control Code

Decimal

Hex

FNC1

134

0x86

FNC2

129

0x81

FNC3

128

0x80

FNC4

132

0x84

 

Example: "3022<FNC1>21123456789012"

 

Forced Switching of Character Sets

Whilst the barcode library switches the character sets (A/B/C) automatically as required, it is also possible to force characters to be coded in a given character set by using the following values as code selectors within the barcode text:

Character Set

Decimal

Hex

CODE A

192

0xC0

CODE B

193

0xC1

CODE C

194

0xC2

NOTE: For code C, two digits must follow, since digits in code C are encoded in pairs. If a code C selector is not followed by at least two digits, no barcode is drawn.

Example (C/C++ notation): "\xC0" "1" "\xC0" "2" "\xC0" "3"

Here, the CODE A is put in front of each digit (1, 2 and 3), so each digit is coded in the character set A.

 

Additional Information

If sending parcels with UPS you should take care that codes of type 128 are not visible on the outside of the parcel, otherwise they could be mismatched by automated systems with the UPS parcel-labels.