In UPC-A barcode symbology, the 12th digit is known as check digit and it is used by the scanner to determine if it scanned the number correctly or not.
the check digit is calculated as follows:
1.Add the digits in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three.
2.Add the digits in the even-numbered positions (second, fourth, sixth, etc.) to the result.
3.Find the result modulo 10 (i.e. the remainder when divided by 10.. 10 goes into 58 5 times with 8 leftover).
4.If the result is not zero, subtract the result from ten.
For example, in a UPC-A barcode "03600029145x" where x is the unknown check digit, x can be calculated by
adding the odd-numbered digits (0 + 6 + 0 + 2 + 1 + 5 = 14),
multiplying by three (14 × 3 = 42),
adding the even-numbered digits (42 + (3 + 0 + 0 + 9 + 4) = 58),
calculating modulo ten (58 mod 10 = 8),
subtracting from ten (10 − 8 = 2).
The check digit is thus 2.
What is the logic behind calculating 'check digit' in such manner?
Can't two different combination of digits produce the same check digit?
Yes. But that's not really the point. If the given check digit doesn't agree with the value computed from the other digits, then there's an inconsistency, so something is wrong. Either the check digit is wrong, or some of the other digits are wrong.
If the check digit is correct, this doesn't guarantee that the other digits are correct. There are various check-digit algorithms. They are designed so that simple common errors (like one digit wrong, or a transposition of two digits) will cause a change in the calculated check digit. So, if the check digit is correct, at least you know that no simple errors of this sort have occurred. Different algorithms target different types of errors.