## Barcode Encoding

Barcodes have been born in 1973 along with the UPC encoding. Barcodes are graphical, machine readable representations of the UPC, its variants and extensions.

In a barcode, each digit of an encoding is represented by seven black or white bars of equal size. Visually, two or more adjacent black bars appear as a single wide bar; white bars appear as space separators (also of varying size) between the black bars. If we call such wide (black or white) bars generalized bars, then, as a rule, a digit's representation always consists of four such generalized bars, which by necessity, interlace: either white-black-white-black or black-white-black-white.

Possible variants of 7-bar representation are shown in the diagram below.

An UPC-A code consists of twelve digits that are split into six left and six right digits. The digits in the two groups are barcoded differently. To barcode the first six (left) digits we use the "Left side (odd parity)" representation. For the next six (right) digits, use the "Right side" representation. One can easily observe that the difference between the two is in exchange of colors: white bars in one are black in the other, and vice versa. All twelve digits are represented by seven bars each, although on a barcode label the first and the last digits are place outside the barcode whilst the "middle" 10 digits are drawn beneath the barcode.

In the EAN-13 encoding the situation is somewhat different. In an EAN-13 code, the first digit does not have a barcode representation of its own, but its value has an effect on the representation of the next six digits. The entries in the following table refer to the "Left side (odd parity)" and the "Left side (even parity)" tables above.

(Note that the "Left side (even parity)" barcodes are the mirror images of the corresponding "Right side" barcodes.)

Left side 6 digits 1 2 3 4 5 First numbersystem digit odd odd odd odd odd odd odd odd even odd even even odd odd even even odd even odd odd even even even odd odd even odd odd even even odd even even odd odd even odd even even even odd odd odd even odd even odd even odd even odd even even odd odd even even odd even odd

As you can observe, UPC-A is easily (and commonly) embedded into EAN-13 by prepending a 0 as the first digit.

Besides the aforementioned fact that every digit's barcode consists of four bars, we may make additional observations:

1. First of all, left side barcodes of either parity are of the form white-black-white-black and thus end in a black bar. The right side barcodes are of the form black-white-black-white and end in a space.

2. No (generalized) bar nor space is wider than four (regular) bars.

Any barcode starts and ends with three "guard bars": black-white-black. Barcodes corresponding to "two-halves" encodings, like the UPC-A and EAN-13, also feature a middle guard in the form white-black-white-black-white.

 63195820