# Checkdigit

• 06-12-2010, 04:15 AM
saramathew
Checkdigit
How do you calculate a check digit using MODULUS 10.
• 06-12-2010, 04:28 AM
Norm
Quote:

using MOD 10 in java
Does that mean there are only 10 different values for the check digit? vs 256
• 06-12-2010, 04:51 AM
Norm
Quote:

sum of all the digits in the code including the check digit are divisible by 10
Ok. The string consists only of digits.
So add them up and do a modulus 10 and see if the results is 0.
• 06-12-2010, 05:58 AM
Norm
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.

What is the code you posted supposed to do? It seems to print out :s and |s and spaces
• 06-12-2010, 06:07 AM
Norm
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 PM
Norm
Quote:

how to get the check digit for 1234
What is the check code 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
1+2+3+4 = 10 which is evenly divisible by 10 so the checkdigit would be 0.
For 123 then the checkdigit would be 4
• 06-12-2010, 02:33 PM
HerrK.
Quote:

Originally Posted by Norm
For 123 then the checkdigit would be 4

1+2+3 = 6, 6 % 10 = 4?! I don't think so ;)
• 06-12-2010, 03:15 PM
JosAH
Quote:

Originally Posted by HerrK.
1+2+3 = 6, 6 % 10 = 4?! I don't think so ;)

I don't even know where those barcodes came from in this thread; I'm completely lost ...

kind regards,

Jos
• 06-12-2010, 03:54 PM
Norm
Quote:

1+2+3 = 6, 6 % 10 = 4?! I don't think so
to find the checkdigit for the string 123 you add the digits up and find the checkdigit that will make the total 10. 1+2+3 = 6 + 4 = 10
4 is the checkdigit
• 06-12-2010, 04:06 PM
HerrK.
Quote:

Originally Posted by saramathew
How do you calculate a check digit using MODULUS 10.

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 PM
Norm
I took a shortcut and didn't do a modulus 10 of 6.
• 06-12-2010, 04:21 PM
HerrK.
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 PM
Norm
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 PM
JosAH
Quote:

Originally Posted by Norm
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

I got that one: we are searching for a single digit d where (sum+d)%10 == 0 but I still have no idea where those barcodes came from ;-)

kind regards,

Jos