Code39 (also known as Alpha39, Code 9 of 3, Code3/9, Type 39, USS Code39 or USD-3) is a barcode with variable length. It can represent 43 characters, including uppercase Latin letters (A to Z), numbers (0 to 9) and several special characters (-, ., $, /, +,% and spaces). There is also an additional symbol as the termination symbol (marked as “*”). Each character consists of nine parts: five lines and four spaces, three of which are wider (binary 1) and six are narrower. The ratio between narrow and wide is not important, it can be between 1:2 and 1:3.
Code39 itself does not contain a check digit (different from Code 128), but because a single-point error does not correspond to another valid code, it can be regarded as a self-checking code. The most serious disadvantage of Code39 may be its low data density, which requires more space than Code 128. This means that it is not easy to use Code39 barcodes for small products. However, some postal systems still use Code 39 (although our country’s Postal Union recommends using Code 128 in all cases). The advantage of Code39 is that as long as the barcode font is added, the barcode can be printed with the existing printing system, because Code39 does not need to calculate the verification position. And almost all barcode scanners can decode.
The “*” character shown below is not a real codeable character, but a start and end symbol. Its asymmetry allows the reader to determine the direction of the barcode being scanned. This symbol is usually mapped to the “*” character, and will be printed in a human-readable format along with the barcode content.
Code39 characters
Generally speaking, the position of the two thick lines can be regarded as encoding the numbers 1 to 10; and the position of the wide space (with four possibilities) can be regarded as dividing the characters into four groups (from left to right) :
The remaining four characters consist of only thin lines, three wide spaces, and one narrow space. There are four possible positions for narrow spaces.
For example, the position of the thick line of the letter P (the 16th letter) is the same as the number 6, and the wide space is placed in the position of the “letter (+20)”.
When representing numbers, 0 will be represented by “10” of “number (+0)”. In addition, because there are only six letters (U to Z) in the “letter (+30)” group, the other four positions (36 to 39) in this group are used to represent “-“, “.”, space, and start/ Termination symbol.
The two thick lines use five possible positions using two-out-of-five code (English: Two-out-of-five code) (each digit represents 1, 2, 4, 7 or 0 respectively) to indicate 1 to Number between 10. For example, the number 6 is coded as “|▮▮||”, and the thick lines are at positions 2 and 4 (2+4=6). And the value of “||▮▮|” is 4+7=11, which means the number 0. When encoding the letters (+10 to +30), the formula needs to add “-1”, so the encoding of the letter “A” is “▮|| |▮”, and the corresponding value is 1+10−1=10 .
The following table is the symbol table of Code39. The value of each character (except the start/stop symbols) will be used in the verification algorithm in the next section.
Lines | Wide spaces | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|| ||| | +0 | ||| || | +10 | |||| | | +20 | | |||| | +30 | ||||||
▮|||▮ | 1 | ▮| ||▮ | 1 | 1 | ▮|| |▮ | A | 10 | ▮||| ▮ | K | 20 | ▮ |||▮ | U | 30 |
|▮||▮ | 2 | |▮ ||▮ | 2 | 2 | |▮| |▮ | B | 11 | |▮|| ▮ | L | 21 | | ▮||▮ | V | 31 |
▮▮||| | 3 | ▮▮ ||| | 3 | 3 | ▮▮| || | C | 12 | ▮▮|| | | M | 22 | ▮ ▮||| | W | 32 |
||▮|▮ | 4 | || ▮|▮ | 4 | 4 | ||▮ |▮ | D | 13 | ||▮| ▮ | N | 23 | | |▮|▮ | X | 33 |
▮|▮|| | 5 | ▮| ▮|| | 5 | 5 | ▮|▮ || | E | 14 | ▮|▮| | | O | 24 | ▮ |▮|| | Y | 34 |
|▮▮|| | 6 | |▮ ▮|| | 6 | 6 | |▮▮ || | F | 15 | |▮▮| | | P | 25 | | ▮▮|| | Z | 35 |
|||▮▮ | 7 | || |▮▮ | 7 | 7 | ||| ▮▮ | G | 16 | |||▮ ▮ | Q | 26 | | ||▮▮ | – | 36 |
▮||▮| | 8 | ▮| |▮| | 8 | 8 | ▮|| ▮| | H | 17 | ▮||▮ | | R | 27 | ▮ ||▮| | . | 37 |
|▮|▮| | 9 | |▮ |▮| | 9 | 9 | |▮| ▮| | I | 18 | |▮|▮ | | S | 28 | | ▮|▮| | ␣ td> | 38 |
||▮▮| | 10 | || ▮▮| | 0 | 0 | ||▮ ▮| | J | 19 | ||▮▮ | | T | 29 | | |▮▮| | * | |
||||| | | | | || | $ | 39 | | | || | | / | 40 | | || | | | + | 41 | || | | | | % | 42 |
Each character will be separated by a narrow space. For example, the complete code of the letter “A” will actually add start/stop symbols and become “*A*”, and the corresponding barcode is “| |▮▮|▮|| |▮| |▮▮|”. As long as there are no such spaces, the barcode cannot be read correctly, so the barcode font must contain this narrow space.
Code39 sometimes adds a modulo 43 check digit. This function needs to be turned on in the reader separately. The barcode with check digit is called “Code39 mod 43”.
Each character is assigned a value. You can refer to the above table.
This is how the checksum is calculated:
Code39 can only represent 34 characters. In ASCII Code39, the symbols of 0 to 9, A to Z, “.”, “,” and spaces are the same as those of Code39. Lowercase letters, other punctuation marks and control characters are represented by two Code39 symbols.
Number | Characters | Encoding | Number | Characters | Encoding | Number | Characters | Encoding | Number | Characters | Encoding |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | NUL | %U | 32 | [space] | [space] | 64 | @ | %V | 96 | ` | %W |
1 | SOH | $A | 33 | ! | /A | 65 | A | A | 97 | a | + A |
2 | STX | $ B | 34 | “ | / B | 66 | B | B | 98 | b | + B |
3 | ETX | $ C | 35 | # | / C | 67 | C | C | 99 | c | + C |
4 | EOT | $ D | 36 | $ | / D | 68 | D | D | 100 | d | + D |
5 | ENQ | $ E | 37 | % | / E | 69 | E | E | 101 | e | + E |
6 | ACK | $ F | 38 | & amp; | / F | 70 | F | F | 102 | f | + F |
7 | BEL | $ G | 39 | ‘ | / G | 71 | G | G | 103 | g | + G |
8 | BS | $ H | 40 | ( | / H | 72 | H | H | 104 | h | + H |
9 | HT | $ I | 41 | ) | / I | 73 | I | I | 105 | i | + I |
10 | LF | $ J | 42 | * | / J | 74 | J | J | 106 | j | + J |
11 | VT | $ K | 43 | + | / K | 75 | K | K | 107 | k | + K |
12 | FF | $ L | 44 | , | / L | 76 | L | L | 108 | l | + L |
13 | CR | $ M | 45 | – | – | 77 | M | M | 109 | m | + M |
14 | SO | $ N | 46 | . | . | 78 | N | N | 110 | n | + N |
15 | SI | $ O | 47 | / | / O | 79 | O | O | 111 | o | + O |
16 | DLE | $ P | 48 | 0 | 0 | 80 | P | P | 112 | p | + P |
17 | DC1 | $ Q | 49 | 1 | 1 | 81 | Q | Q | 113 | q | + Q |
18 | DC2 | $ R | 50 | 2 | 2 | 82 | R | R | 114 | r | + R |
19 | DC3 | $ S | 51 | 3 | 3 | 83 | S | S | 115 | s | + S |
20 | DC4 | $ T | 52 | 4 | 4 | 84 | T | T | 116 | t | + T |
21 | NAK | $ U | 53 | 5 | 5 | 85 | U | U | 117 | u | + U |
22 | SYN | $ V | 54 | 6 | 6 | 86 | V | V | 118 | v | + V |
23 | ETB | $ W | 55 | 7 | 7 | 87 | W | W | 119 | w | + W |
24 | CAN | $ X | 56 | 8 | 8 | 88 | X | X | 120 | x | + X |
25 | EM | $ Y | 57 | 9 | 9 | 89 | Y | Y | 121 | y | + Y |
26 | SUB | $ Z | 58 | : | / Z | 90 | Z | Z | 122 | z | + Z |
27 | ESC | % A | 59 | ; | % F | 91 | [ | % K | 123 | { | % P |
28 | FS | % B | 60 | & lt; | % G | 92 | \ | % L | 124 | | | % Q |
29 | GS | % C | 61 | = | % H | 93 | ] | % M | 125 | } | % R |
30 | RS | % D | 62 | & gt; | % I | 94 | ^ | % N | 126 | ~ | % S |
31 | US | % E | 63 | ? | % J | 95 | _ | % O | 127 | DEL | % T,% X,% Y,% Z |