Results 1 to 14 of 14

Thread: Checkdigit

  1. #1
    saramathew is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Default Checkdigit

    How do you calculate a check digit using MODULUS 10.
    Last edited by saramathew; 06-12-2010 at 02:48 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    using MOD 10 in java
    Does that mean there are only 10 different values for the check digit? vs 256

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    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.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    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
    Last edited by Norm; 06-12-2010 at 06:02 AM.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    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 = :|::|
    Last edited by Norm; 06-12-2010 at 06:12 AM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    how to get the check digit for 1234
    What is the check code for 1234?
    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

  7. #7
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    For 123 then the checkdigit would be 4
    1+2+3 = 6, 6 % 10 = 4?! I don't think so ;)

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by HerrK. View Post
    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

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    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

  10. #10
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by saramathew View Post
    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
    Java 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

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    I took a shortcut and didn't do a modulus 10 of 6.

  12. #12
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    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

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,563
    Rep Power
    23

    Default

    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

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •