Others view: Disjoint squares/ ♦ carry look-ahead adder ♦ Welcome ♦ Reversal potential ♦ Mars globe ♦ kepler laws ♦ Dot-Bracket Notation ♦ Kepler laws ♦ welcome ♦

The **Universal Product Code** (**UPC**) is a barcode used in United States and Canada for tracking items in stores^{[1]}. It reliably encodes exactly 12 digits and cannot be used to encode letters or other non digit characters. The last digit of the UPC code is called a check digit^{[2]}.

UPC-A uses as many as seven bits to encode a digit. The bit pattern for each numeral is designed to be as different from others as possible. Also, no pattern has more than four subsequent 1s or 0s in order. This increases reliability of scanning. The code can detect all possible single digit errors and most of (89%) transposition errors.

In total, UPC-A encodes 12 digits as *S* **LLLLLL** *M* **RRRRRR** *E*, where *S* (start) and *E* (end) are the bit pattern 101, *M* (middle) is the bit pattern 01010. These helper patterns are called guard bars. Every **L** (left) and **R** (right) is the mentioned seven bit digit. The encoding always contains 95 bits in total.

Since *S*, *M*, and *E* all include two bars, and each of the 12 digits of the UPC-A barcode consists of two bars and two spaces, all UPC-A barcodes consist of exactly (3 × 2) + (12 × 2) = 30 bars.

The check digit is computed by formula^{[3]}

where *d* is a value of the digit at the given position. The first counts odd positions and the second counts even positions. The first position is assumed to be 1 and is odd. The same formula is used both for UPC-E and UPC-A.

The numbers in the barcode are standardized, agreed prefixes having the following meanings:

- 0, 1, 6, 7, 8: For most products.
- 2: Reserved for items sold by variable weight like fruits or vegetables. In this case, the LLLLL is the item id, and the
**R**RRRR is either the weight or the price, with the first**R**determining which. - 3: Drugs by National Drug Code number.
- 4: Loyalty cards or store coupons.
- 5: Discount coupons that cannot be doubled or tripled.
- 9: Discount coupons that can be doubled or tripled.

UPC-E is used for smaller packages where a full 12-digit barcode does not fit. This symbology uses a 3 digits per section instead of 6 and does not use middle guard bars. For example a UPC-E barcode with the number 0745982 would expand to the UPC-A 007459000087^{[4]}.

UPC-E check digits are calculated using this expanded string in the same way as used by UPC-A. The exact algorithm of the conversion is the following:

- If the code length is 7, discard the last digit. If it is 8, discard both first and last digit.
- Let
*d1 .. d6*be the digits at the corresponding positions of the code, processed with the previous step. - If
*d6*is one of*(0,1,2)*the left part is*d1 + d2 + d6 + 00*, and the right part is*00 + d3 + d4 + d5*(here and below + means concatenation, not addition) - Else if
*d6 = 3*then the left part is*d1 + d2 + d3 + 00*and the right part is*000 + d4 + d5*. - Else if
*d6 = 4*then the left part is*d1 + d2 + d3 + d4 + 0*and the right part is*0000 + d5*. - Else the left part is
*d1 + d2 + d3 + d4 + d5*and the right part is*0000 + d6*. - The UPC-A code is
*0 + left part+ right part + check digit*, where the check digit is computed as above.

Using LaTeX, this can be written in the form:

and

UPC-A Bar code symbols can be printed at various densities to accommodate variety of printing and scanning processes. The significant dimensional parameter is called X-dimension, the ideal width of single module element. The X-dimension has to be constant in UPC-A symbol. The width of each bar (dark bar) and space (light bar) is determined by multiplying the X-dimension by the module width of each dark bar or light bar (1,2,3, or 4).

^{1 }Wikipedia article on UPC^{2 }The check digit calculator^{3 }Barcode computing code, Python, GPLv3. Contains code to compute check digit and to convert between UPC-E and UPC-A.^{4 }Web for to convert UPC-E to UPC-A