The Mudcat Café TM
Thread #20484   Message #213960
Posted By: Jon Freeman
18-Apr-00 - 06:46 PM
Thread Name: Help: UPC codes
Subject: RE: Help: UPC codes
Sandy, useless info for you. I'm not sure what system is used for bar codes but check digits are not that complicated.

First one needs to decide on a modulus and a series of weights to multiply the numbers by.

Lets say the weights we have chosen to use for a five digit number are set at 6,5,4,3,2 and we are using modulus 11.

We have a number say 31602 that we want to create a check digit for using our system.

The first step is to multiply each digit by it's corresponding weight:

ie 6x3=18, 5x1=5, 4x6=24, 3x0=0, 2x2=4

Add these together = 51 and divide by the modulus (11) = 4 remainder 7.

Subtract the remainder from the modulus to get the check digit ie. 11-7=4

So in this case, the final number with the check digit is 316024.

The test comes when the number is read back. The same calculations are used but this time with the check digit included (the weight for a check digit is 1). This gives us 51 as calculated previously + (4x1) = 55. The remainder when divided by the modulus (55/11) is 0. If the remainder is anything other than 0, this indicates an error in input (maybe a number transposed, wrongly read etc).

It may seem laborious by hand but computers love this sort of work and it takes them no time to calculate them.

Jon