How do you calculate a check digit using MODULUS 10.

Printable View

- 06-12-2010, 04:15 AMsaramathewCheckdigit
How do you calculate a check digit using MODULUS 10.

- 06-12-2010, 04:28 AMNormQuote:

using MOD 10 in java

- 06-12-2010, 04:51 AMNormQuote:

sum of all the digits in the code including the check digit are divisible by 10

So add them up and do a modulus 10 and see if the results is 0. - 06-12-2010, 05:58 AMNorm
Convert each of the digit characters to its int value. For example "5" gives 5

See the Integer class for a method that does this.

Then add them up.

What is the code you posted supposed to do? It seems to print out :s and |s and spaces - 06-12-2010, 06:07 AMNorm
Sorry, I got lost. What happened to the check digit?

If the following is true, how did you get the answer: Bar code: :|:: :|||: :||:

1 = :::||

2 = ::|:|

3 = ::||:

4 = :|::| - 06-12-2010, 02:23 PMNormQuote:

how to get the check digit for 1234

Quote:

value is chosen so that the sum of all the digits in the code including the check digit are divisible by 10

For 123 then the checkdigit would be 4 - 06-12-2010, 02:33 PMHerrK.
- 06-12-2010, 03:15 PMJosAH
- 06-12-2010, 03:54 PMNormQuote:

1+2+3 = 6, 6 % 10 = 4?! I don't think so

4 is the checkdigit - 06-12-2010, 04:06 PMHerrK.
Well, modulus 10 does not mean to find the digit that will make a total of ten. Let's assume you want to compute the checkdigit of the string 12345:

1+2+3+4+5 = 15, is the checkdigit -5?

Modulus is defined as the remainder of the division, so 1+2+3 (6) MODULUS 10 what be 6 and 15 MODULUS 10 is 5. So you could be sure, that any number you receive is in between 0..9 or in general MODULUS n will return any number in 0 to (n-1).

In Java you could compute the modulus by using the % operator

Code:`int checksum;`

checksum = (1+2+3) % 10; // checksum == 6

checksum = (1+2+3+4) % 10; // checksum == 0

checksum = (1+2+3+4+5) % 10; // checksum == 5

- 06-12-2010, 04:12 PMNorm
I took a shortcut and didn't do a modulus 10 of 6.

- 06-12-2010, 04:21 PMHerrK.
You took a shortcut? I don't get what you want to say.

Excuse me, but this is a forum. The posts should help people to get a solution for a problem. The original post asks for a solution to get the modulus by 10 in Java. At some point were getting into some barcodes (and I totaly agree to JosAh, no one has a clue what the barcodes are all about) and now we have shortcuts to the a total of 10?!

I don't know how this should help anyone who wants to know how to get the modulus of 10. And if you have something like a barcode, there is a defined amount of checkdigits. If the last digit of the code is a checkdigit, you have to ensure that this digit is valid (e.g. for decimal numbers in 0 to 9, which could be computed by any value modulus 10). I really can't see what this shortcut is about or even why we are talking about bar codes and stuff. Please add the needed information in future to ensure that this post might help others, too, that have the same (or a close) problem - 06-12-2010, 04:28 PMNorm
By shortcut I meant I should have more fully explained my example. I left off the part of doing 6 modulus 10 being equal to 6 as being obvious.

I thought the problem was how to compute the checkdigit for a string of digits. The digit chosen was to result in the sum of all the digits mod 10 being 0. For example: 1+2+3 = 6 + 4 = 10 mod 10 = 0 - 06-12-2010, 04:48 PMJosAH