check digit : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

check digit
Dating back to keypunches, id numbers have an appended check digit used to ensure that the number was keyed properly. The various types of bar code such as the UPC (Universal Product Code) you see on grocery items all have a check digit. The basic idea is if you transpose or mistype a character in entering a number the checksum won’t match the one that should be there according to the calculations. One of the most common schemes is called mod 10, used for all credit card numbers and the Canadian SIN (Social Insurance Number). Here is how to calculate a mod 10 check digit by the manual method:

e.g. to compute the expected check digit 7 for: 706-511-22?

digit 7 0 6 5 1 1 2 2 ?
multiplier 1 2 1 2 1 2 1 2  
result 7 0 6 10
1
1 2 2 4   horizonal sum = 23
23 MOD 10 = 3
10 - 3 = 7 — the check digit

Note that the two digits of the multiplication results must be added before doing the sum.

Here is method more amenable to computer calculation:

e.g. to compute see if the check digit is as expected: 706-511-227

digit 7 0 6 5 1 1 2 2 7
multiplier 1 z 1 z 1 z 1 z 1
result 7 0 6 1 1 2 2 4 7 horizonal sum = 30
30 MOD 10 had better = 0. What do you know, it is!
Here is the Java code to do this where z is a function that doubles and adds digits, defined mathematically more efficiently

This page is posted
on the web at:

http://mindprod.com/jgloss/checkdigit.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\checkdigit.html
logo
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[54.91.243.175]
You are visitor number