The universal product code (UPC) is another familiar barcode that incorporates a system of error detection. The standard code used on items sold in American supermarkets (with the exception of items that are small and typically cylindrical, for which a special variant code was developed) consists of 11 information digits and a check digit. (The European version of this system is somewhat different.) Originally, the code was organized into four blocks, but because of the popularity of the code and the breadth of its use, the original standard has had to be modified so as to flexibly code the desired information. In any case the check digit works as follows: add the digits in the odd positions of the string which forms the code sequence, and multiply by 3; now take the digits in the even positions, sum them, and add to the previous answer. Finally, the check digit is chosen so that when it is added to the value, the result is a number which is divisible by 10 (ends in a zero).
Example:
Find the check digit (i.e. the value for the ? ) for the UPC number:
3 05212 90500 ?
The digits in the odd positions are 3, 5, 1, 9, 5, and 0. These sum to 23, which tripled yields 69. The digits in the even positions are 0, 2, 2, 0, and 0. These sum to 4, which, when added to 69, gives 73. Thus, the check digit is 7, because 73 + 7 = 80 is divisible by 10.
Symbolically, if we denote the code string, including the check digit by:
u_{1}u_{2}u_{3}u_{4}u_{5}u_{6}u_{7}u_{8}u_{9}u_{10}u_{11}u_{12}
We compute the check digit u_{12} so that:
R = 3(u_{1} + u_{3} + u_{5} + u_{7} + u_{9} + u_{11 })+ (u_{2} + u_{4} + u_{6} + u_{8} + u_{10} + u_{12})
is congruent to zero modulo 10. If one is dealing with a legal UPC code, then R 0 mod 10 holds for the code.