EAN-13 and UPC-A barcodes are widely used to identify retail items. The barcodes encode 13-digit and 12-digit number respectively. At the first glance, it is easy to create them. Unfortunately if you are using the font-based solution, it is not that easy as you may think. There are a couple of reasons:
To allow space efficiency, the same digit is coded with different patterns depending on its position in the barcode.
The same bar/space pattern may have or not have underlying text.
At last, font design requires every pattern to be represented by an unique character. You can not have one character representing multiple patterns.
As a matter of the complicity, we found that we have to use all printable ASCII characters, plus 10 extended characters to represent all bar/space patterns. This character set is far larger than the 10-digit numeric set. For every digit, there are five different encodings:
Left-hand Odd (LO)
Left-hand Even (LE)
Right-hand (R)
Supplement Odd (SO)
Supplement Even (SE)
In addition to the encodings, the unqiue printing requirement adds three variants to exsiting patterns:
With text below
Without text below
With text above
To allow user easily derive the encoding, we use a standard US-English keyboard [1] to map patterns to characters.
A. To print left-hand odd encodings without below text, use the first line of characters on a keyboard:
! @ # $ % ^ & * ( )
B. To print left-hand odd encodings with below text, use the second line of characters - that is, numbers 0-9:
1 2 3 4 5 6 7 8 9 0
C. To print left-hand even encodings without below text, use the third line of characters in captial case:
Q W E R T Y U I O P
D. To print left-hand even encodings with below text, we still use the third line of characters, however in lower case:
q w e r t y u i o p
E. Right-hand encodings do not have even/odd parity. To print right-hand encodings, use the fourth line. Captial letters print patterns without below text: [2]
A S D F G H J K L :
F. And lower case letters print patterns with underlying text:
a s d f g h j k l ;
G. Supplemental encodings use the last line, with capital letters printing odd encodings:
Z X C V B N M < > ?
H. And lower-case letters print even encodings:
z x c v b n m , . /
I. At last, these text-only symbols are printable with extended characters
with values ranging from 0xc0 ~ 0xc9
:
À Á Â Ã Ä Å Æ Ç È É
Because all printable ASCII characters are used up, we have to map these
symbols to extended characters.
On systems that a different character set other than Latin 1 is used,
you will need to enter their
corresponding characters. For example, in Eastern European languages (Windows
code page 1250), character U+0154
(Latin character R with Acute) correspondes to value 0xc0
.
Now that we have introduced character mappings, we proceed to explain how EAN-13 and UPC-A are encoded.
An EAN-13 barcode encodes a 13-digit number. This number has a check digit at the end based on modulo 10 algorithm. Using Morovia UPC/EAN/Bookland fonts, a total number of 15 characters are needed to encode the whole barcode symbol, as depicted below:
The 16 characters are divided into six parts, as follows:
Leading character, encoded with scheme I;
Start character, represented by open square bracket symbol
[
;Left-hand encodings
Central-guard character, represented by the virtical bar symbol
|
;Right-hand encodings
Stop character, printable with close square bracket symbol
]
.
The leading character uses mapping scheme I. The character
corresponding to this pattern is É, character value 0xc9
. On Windows, this character can be entered by
holding ALT key and using the numeric keyboard to type 201
. Here 201
is the decimal value of 0xc9.
The start character follows the leading character immediately.
To enter this character, type [
(open square bracket).
The next 6 characters encode the first 7 digits using the left-hand encoding scheme. You might wonder how it can be done - here is the trick: the first digit is not converted into any characters; however its value determines the parity of next 6 digits. Remember that left-hand encodings have two parities - even and odd.
Table 1. Left-hand Parity Lookup Table
First Digit | Second Digit Encoding | 3rd | 4th | 5th | 6th | 7th |
---|---|---|---|---|---|---|
0 | Left-hand Encoding, Odd | Odd | Odd | Odd | Odd | Odd |
1 | Odd | Even | Odd | Even | Even | |
2 | Odd | Even | Even | Odd | Even | |
3 | Odd | Even | Even | Even | Odd | |
4 | Even | Odd | Odd | Even | Even | |
5 | Even | Even | Odd | Odd | Even | |
6 | Even | Even | Even | Odd | Odd | |
7 | Even | Odd | Even | Odd | Even | |
8 | Even | Odd | Even | Even | Odd | |
9 | Even | Even | Odd | Even | Odd |
In our case, the first digit is 9, the encoding pattern for
digit 2 to digit 7 should be OEEOEO
according to the
table above. Because all of them print human readable text below, the
shcemes B and D are used. The left-hand odd encodings for digits 7 and 5
are themselves (7 and 5). The left-ahdn even encodings for digits 8, 0 and
3 are i, p and e respectively. Adding them all together we get the barcode
string for this part: 7ip7e5
.
The right-hand encodings do not have parity. Since they
all have text below, scheme F is used. Therefore, the barcode string for 200449
is haakds
.
A UPC-A barcode encodes 12 digits with the last digit served as check digit. The UPC-A encoding is very similiar to EAN-13, except the following differences:
UPC-A implies a country prefix
0
. From Table 1, “Left-hand Parity Lookup Table”, it means that the first 6 digits are all encoded with odd parity.The first digit is converted into bar/space patterns, however, it does not have below text. The text is instead placed outside the barcode.
The last digit is also converted into bar/space patterns, however, it does not have below text either and the text is placed at the end of the barcode.
A UPC-A barcode string consist of 17 character, and is divided into 6 parts:
The leading character uses mapping scheme I. To print the text-ony symbol for digit 0, use extended character À (character value 0xc0).
The start character is mapped to open square bracket [
,
in the same way as in EAN-13.
This portion actually contains 6 characters, the same as in EAN-13.
Since UPC-A numbers have an implicit country code of 0
,
the encoding schema are all odd according to Table 1, “Left-hand Parity Lookup Table”.
However, note that the first digit is encoded without human readable text below,
so it must be coded in scheme A. Therefore, the barcode
string for the first part 021898
is )21898
.
The following 6 digits are encoded with right-hand encoding schema.
The first 5 digits print their human readable text below and are coded
in schema E. However, the last digit does not print text below, so it must be
coded with schema F. Therefore, the barcode string for 623812
is hsdkaS
.
The last digit of a UPC-A number also has a text form which uses mapping scheme I. Digit 2 is mapped to Â.
[1] Keyboards in other languages may have different layouts.
[2] When applying on punctuation symbols, the "capital" means that
these characters are accessed by pressing the key while holding the Shift.
For example, collon :
is in the same class as upper case A
while semicolon ;
is in the
same class as lower case a
.