Why three sets?

In the EAN/UPC family, each digit 0-9 has three different 7-module bar/space patterns - the L-code (odd parity), the G-code (even parity), and the R-code. Most beginners expect one pattern per digit; the three-pattern design is what gives the family two valuable properties:

  1. Orientation detection. The R-codes are the bitwise complement of the L-codes. That asymmetry lets a scanner detect whether it's reading the symbol left-to-right or right-to-left and decode either way. (Walk past a checkout scanner upside-down - the beep still happens.)
  2. Implicit 13th digit. EAN-13 prints only 12 patterns but encodes 13 digits. The 13th (leading) digit is carried by the choice between L-code and G-code on each of the six left-half digit positions - that's the parity selection trick.

UPC-A and EAN-8 don't use the parity-selection trick (they always pick L-code for left-half digits and R-code for right-half digits), but they share the same pattern tables. UPC-E uses parity selection too.

The patterns

All three sets are exactly 7 modules per digit. 1 is a dark module (bar); 0 is a light module (space). Source: ISO/IEC 15420 Tables 1-3.

L-code patterns - left-half digits when parity = L (and always for UPC-A / EAN-8 left half)
Digit Bits Pattern
00001101
10011001
20010011
30111101
40100011
50110001
60101111
70111011
80110111
90001011
G-code patterns - left-half digits when parity = G (only used by EAN-13 and UPC-E)
Digit Bits Pattern
00100111
10110011
20011011
30100001
40011101
50111001
60000101
70010001
80001001
90010111
R-code patterns - right-half digits in all of EAN-13, EAN-8, UPC-A
Digit Bits Pattern
01110010
11100110
21101100
31000010
41011100
51001110
61010000
71000100
81001000
91110100

How the three sets relate

  • R-code = NOT(L-code). Bit-for-bit, every R pattern is the inversion of the L pattern for the same digit. Compare L[0] 0001101 with R[0] 1110010 - every bit is flipped. That's how a scanner reading the right half knows it's the right half: every "1 module" in the R-pattern is light in the L-pattern.
  • G-code = reverse(R-code). Each G pattern is the R pattern read right-to-left. Compare R[0] 1110010 with G[0] 0100111 - same bits, opposite order. That makes the G-code "even parity" (an even number of 1-bits) which is the property the parity-selection table exploits.
  • L-code parity is always odd. Every L-pattern has an odd number of 1-bits (count them: 0001101 = three 1-bits). G-patterns always have an even number. The parity selection is literally "is this digit odd-parity or even-parity?"

Where each set appears

SymbologyLeft halfRight half
EAN-13 Mix of L and G chosen by the parity-selection table R only
EAN-8 L onlyR only
UPC-A L onlyR only
UPC-E Mix of L and G chosen by parity selection on the implicit number system + check digit(no right half - UPC-E has only 6 data digits)

Key standards

Related