169
• Check Digit https://store.theartofservice.com/the-check-digit- toolkit.html

Check Digit

Embed Size (px)

Citation preview

Page 1: Check Digit

• Check Digit

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 2: Check Digit

International Standard Book Number Check digits

1 A check digit is a form of redundancy check used for error detection, the

decimal equivalent of a binary check bit. It consists of a single digit

computed from the other digits in the message.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 3: Check Digit

International Standard Book Number ISBN-10 check digits

1 The 2001 edition of the official manual of the International ISBN

Agency says that the ISBN-10 check digit – which is the last digit of the

ten-digit ISBN – must range from 0 to 10 (the symbol X is used for 10), and must be such that the sum of all the

ten digits, each multiplied by its (integer) weight, descending from 10

to 1, is a multiple of 11.https://store.theartofservice.com/the-check-digit-toolkit.html

Page 4: Check Digit

International Standard Book Number ISBN-10 check digits

1 Formally, using modular arithmetic,

we can say:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 5: Check Digit

International Standard Book Number ISBN-10 check digits

1 It is also true for ISBN-10's that the sum of all the ten digits, each

multiplied by its weight in ascending order from 1 to 10, is a multiple of

11. For this example:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 6: Check Digit

International Standard Book Number ISBN-10 check digits

1 The two most common errors in handling an ISBN (e.g., typing or writing it) are a single

altered digit or the transposition of adjacent digits. It can be proved that all possible valid ISBN-10's have at least two digits different from each other. It can also be proved that there are no pairs of valid ISBN-10's with eight identical digits and two transposed

digits. (These are true only because the ISBN is less than 11 digits long, and because 11 is

prime.)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 7: Check Digit

International Standard Book Number ISBN-10 check digits

1 The ISBN check digit method therefore ensures that it will always be possible to detect these two most common types of error, i.e. if either of these types of error has occurred, the result will never be a

valid ISBN - the sum of the digits multiplied by their weights will never be a multiple of

11. However, if the error occurs in the publishing house and goes undetected, the

book will be issued with an invalid ISBN.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 8: Check Digit

International Standard Book Number ISBN-10 check digits

1 In contrast, it is possible for other types of error, such as two altered

non-transposed digits, or three altered digits, to result in a valid ISBN number (although it is still unlikely).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 9: Check Digit

International Standard Book Number ISBN-10 check digit calculation

1 Modular arithmetic is convenient for calculating the check digit using modulus 11. Each of the first nine digits of the ten-

digit ISBN – excluding the check digit, itself – is multiplied by a number in a sequence

from 10 to 2, and the remainder of the sum, with respect to 11, is computed. The

resulting remainder, plus the check digit, must equal 11; therefore, the check digit is 11 minus the remainder of the sum of the

products.https://store.theartofservice.com/the-check-digit-toolkit.html

Page 10: Check Digit

International Standard Book Number ISBN-10 check digit calculation

1 For example, the check digit for an ISBN-10 of 0-306-40615-? is calculated as follows:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 11: Check Digit

International Standard Book Number ISBN-10 check digit calculation

1 Thus the check digit is 2, and the complete sequence is ISBN 0-306-

40615-2. The value required to satisfy this condition might be 10; if

so, an 'X' should be used.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 12: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 The 2005 edition of the International ISBN Agency's official manual

describes how the 13-digit ISBN check digit is calculated.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 13: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 The calculation of an ISBN-13 check digit begins with the first 12 digits of the

thirteen-digit ISBN (thus excluding the check digit itself). Each digit, from left to right, is alternately multiplied by 1 or 3,

then those products are summed modulo 10 to give a value ranging from 0 to 9.

Subtracted from 10, that leaves a result from 1 to 10. A zero (0) replaces a ten (10), so, in all cases, a single check digit results.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 14: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 For example, the ISBN-13 check digit of 978-0-306-40615-? is calculated as follows:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 15: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 Thus, the check digit is 7, and the complete sequence is ISBN 978-0-306-40615-7.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 16: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 Formally, the ISBN-13 check digit calculation is:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 17: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 The ISBN-10 formula uses the prime modulus 11 which avoids this blind

spot, but requires more than the digits 0-9 to express the check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 18: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 Additionally, if the sum of the 2nd, 4th, 6th, 8th, 10th, and 12th digits is tripled then added to the remaining digits (1st, 3rd, 5th, 7th, 9th, 11th, and 13th), the total will always be

divisible by 10 (i.e., end in 0).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 19: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 public static boolean isISBN13Valid(String

isbn) {

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 20: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 check += Integer.valueOf(isbn.substring(i, i + 1));

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 21: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 function isValidISBN13(ISBNumbe

r) {

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 22: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 sum = transformed_digits.r

educe(:+)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 23: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 check = (10 - (sum(int(digit) * (3 if idx % 2 else 1) for idx, digit in

enumerate(isbn[:12])) % 10)) % 10

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 24: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 FUNCTION validate_isbn_13(isb

n VARCHAR2) RETURN INTEGER IS

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 25: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 modular INTEGER;

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 26: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 IF modular = 0 THEN

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 27: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 reminder := 10 - modular;

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 28: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 IF TO_CHAR( reminder ) = SUBSTR(isbn, 13, 1 )

THEN

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 29: Check Digit

International Standard Book Number ISBN-13 check digit calculation

1 # Bourne-Again Shell

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 30: Check Digit

International Standard Music Number - Check digit

1 To calculate the check digit, each digit of the ISMN is multiplied by a weight, alternating 1 and 3 left to right. These weighted digits are

added together. The check digit is the integer between 0 and 9 that makes the sum a multiple of 10.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 31: Check Digit

ISO/IEC 7812 - Check digit

1 The final digit is a check digit which is calculated using the Luhn

algorithm, defined in Annex B of ISO/IEC 7812-1.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 32: Check Digit

ISO 6346 - Check Digit

1 The check digit consists of one numeric digit providing a means of

validating the recording and transmission accuracies of the owner

code and serial number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 33: Check Digit

International Bank Account Number - Generating IBAN check digits

1 According to the ECBS "generation of the IBAN shall be the exclusive

responsibility of the bank/branch servicing the account". The ECBS document replicates part of the

ISO/IEC 7064:2003 standard as a method for generating check digits in

the range 02 to 98. Check digits in the ranges 00 to 96, 01 to 97, and 03

to 99 will also provide validation of an IBAN, but the standard is silent as to whether or not these ranges may

be used.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 34: Check Digit

International Bank Account Number - Generating IBAN check digits

1 Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 35: Check Digit

International Bank Account Number - Generating IBAN check digits

1 Replace the two check digits by 00 (e.g. GB00 for the UK)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 36: Check Digit

International Bank Account Number - Generating IBAN check digits

1 Move the four initial characters to the end of the string

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 37: Check Digit

International Bank Account Number - Generating IBAN check digits

1 Replace the letters in the string with digits, expanding the string as

necessary, such that A or a = 10, B or b = 11, and Z or z = 35. Each alphabetic character is therefore

replaced by 2 digits

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 38: Check Digit

International Bank Account Number - Generating IBAN check digits

1 Calculate mod-97 of the new number, which

results in the remainder

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 39: Check Digit

International Bank Account Number - Generating IBAN check digits

1 Subtract the remainder from 98, and use the result for the two check

digits. If the result is a single digit number, pad it with a leading 0 to

make a two-digit number

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 40: Check Digit

Codabar - Check digit

1 Because Codabar is self-checking, most standards do not define a check digit.http://mdn.morovia.com/manuals/bax3/shared.bartech.php#Symbolo

gy.Codabar

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 41: Check Digit

Codabar - Check digit

1 Some standards that use Codabar will define a check digit, but the

algorithm is not universal. For purely numerical data, such as the library barcode pictured above, the Luhn

algorithm is popular.http://www.makebarcode.co

m/specs/codabar.html

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 42: Check Digit

Codabar - Check digit

1 When all 16 symbols are possible, a simple modulo-16 checksum is

used.http://www.barcodesymbols.com/codabar.htm The values 10 through 19 are assigned to the

symbols –$:/+.ABCD, respectively.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 43: Check Digit

Universal Product Code - Check digits

1 In the UPC-A system, the check

digit is calculated as follows:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 44: Check Digit

Universal Product Code - Check digits

1 # Add the digits in the Even and odd numbers|odd-numbered positions

(first, third, fifth, etc.) together and multiply by three.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 45: Check Digit

Universal Product Code - Check digits

1 # Add the digits in the even and odd numbers|even-numbered positions (second, fourth, sixth, etc.) to the

result.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 46: Check Digit

Universal Product Code - Check digits

1 # Find the result modulo operation|modulo 10 (i.e. the remainder when

divided by 10.. 10 goes into 58 5 times with 8 leftover).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 47: Check Digit

Universal Product Code - Check digits

1 # If the result is not zero, subtract the result

from ten.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 48: Check Digit

Universal Product Code - Check digits

1 For example, in a UPC-A barcode 03600029145'x' where 'x' is the unknown check digit, 'x' can be

calculated by

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 49: Check Digit

Universal Product Code - Check digits

1 *adding the odd-numbered digits

(0+6+0+2+1+5 = 14),

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 50: Check Digit

Universal Product Code - Check digits

1 *calculating modulo ten (58mod10 = 8),

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 51: Check Digit

Universal Product Code - Check digits

1 *subtracting from ten (10minus;8 = 2).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 52: Check Digit

Universal Product Code - Check digits

1 This should not be confused with the numeral X which stands for a value of 10 in modulo 11, commonly seen in the International Standard Book

Number|ISBN check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 53: Check Digit

Code 128 - Check digit calculation

1 The remainder of the division is the check digit's 'value' which is then

converted into a character (following the instructions given Code

128#Conversion to char|below) and appended to the end of the barcode.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 54: Check Digit

Code 128 - Check digit calculation

1 For example, in the following table, the code 128 variant A checksum

value is calculated for the alphanumeric string PJJ123C

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 55: Check Digit

Code 128 - Calculating check digit with multiple variants

1 As Code 128 allows multiple variants, as well as switching between

variants within a single barcode, it is important to remember that the

absolute Code 128 value of a character is completely independent of its value within a given variant. For instance the Variant C value 33 and

the Variant B value A are both considered to be a Code 128 value of

33, and the check digit would be computed based on the value of 33 times the character's position within

the barcode.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 56: Check Digit

British Cattle Movement Service - Check Digit

1 The check digit for a cow’s ear tag is calculated by dividing the number obtained from the herd mark and

animal number by 7 and adding one to the remainder. Take UK herd

number 303565 cow number 01234. We work out the check digit as

follows:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 57: Check Digit

MSI Barcode - Check digit calculation

1 The MSI barcode uses one of five possible schemes for calculating a check digit:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 58: Check Digit

MSI Barcode - Check digit calculation

1 * Modulo operation|Mod 10 (most

common)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 59: Check Digit

MSI Barcode - Mod 10 Check Digit

1 When using the Mod 10 check digit algorithm, a string to be encoded

1234567 will be printed with a check digit of 4:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 60: Check Digit

MSI Barcode - Mod 10 Check Digit

1 [http://publib.boulder.ibm.com/infocenter/printer/v1r1/index.jsp?

topic=/com.ibm.printers.afpproducts/

com.ibm.printers.ppfaug/ib6p8mst334.htm IBM Printing

Systems Information Center - Check Digit Calculation Method], IBM.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 61: Check Digit

MSI Barcode - Mod 10 Check Digit

1 uses the Luhn algorithm.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 62: Check Digit

MSI Barcode - Mod 11 Check Digit

1 2

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 63: Check Digit

MSI Barcode - Mod 11 Check Digit

1 This example is using the IBM modulo 11 algorithm with a weighting pattern of

(2,3,4,5,6,7)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 64: Check Digit

MSI Barcode - Mod 11 Check Digit

1 Let X = the final product of the string

to encode.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 65: Check Digit

MSI Barcode - Mod 11 Check Digit

1 3. Mod the sum by 11, subtract the result from 11, and then apply the mod 11 function

again.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 66: Check Digit

MSI Barcode - Mod 1010 check digit

1 Simply calculate the Mod 10 check digit the first time and then calculate it again with the previous result and append the result of the second Mod

10 Calculation to the string to be encoded.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 67: Check Digit

MSI Barcode - Mod 1110 check digit

1 Same as Mod 1010 but the first calculation should be a Mod 11

Check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 68: Check Digit

International Mobile Equipment Identity - Check digit computation

1 The last number of the IMEI is a check digit calculated using the Luhn algorithm.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 69: Check Digit

International Mobile Equipment Identity - Check digit computation

1 According to the [http://www.gsma.com/documents/ts-06-6-0-imei-allocation-and-approval-guidelines/20164/ IMEI Allocation and

Approval Guidelines],

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 70: Check Digit

International Mobile Equipment Identity - Check digit computation

1 The Check Digit shall be calculated according to Luhn algorithm|Luhn formula (ISO/IEC 7812). (See GSM 02.16 / 3GPP 22.016). The Check

Digit is a function of all other digits in the IMEI. The Software Version

Number (SVN) of a mobile is not included in the calculation.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 71: Check Digit

International Mobile Equipment Identity - Check digit computation

1 The purpose of the Check Digit is to help guard against the possibility of incorrect entries to the CEIR and EIR

equipment.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 72: Check Digit

International Mobile Equipment Identity - Check digit computation

1 The presentation of the Check Digit both electronically and in printed

form on the label and packaging is very important. Logistics (using bar-

code reader) and EIR/CEIR administration cannot use the Check

Digit unless it is printed outside of the packaging, and on the ME IMEI/Type Accreditation label.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 73: Check Digit

International Mobile Equipment Identity - Check digit computation

1 The check digit is not transmitted over the radio interface, nor is it stored in the EIR database at any

point. Therefore, all references to the last three or six digits of an IMEI refer to the actual IMEI number, to which

the check digit does not belong.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 74: Check Digit

International Mobile Equipment Identity - Check digit computation

1 # Starting from the right, double every other

digit (e.g., 7 → 14).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 75: Check Digit

International Mobile Equipment Identity - Check digit computation

1 Conversely, one can calculate the IMEI by choosing the check digit that would give a sum divisible by 10. For the example IMEI 49015420323751?,

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 76: Check Digit

International Mobile Equipment Identity - Check digit computation

1 To make the sum divisible by 10, we set ? = 8, so the IMEI is 490154203237518.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 77: Check Digit

Check digit

1 A 'check digit' is a form of redundancy check used for Error

detection and correction|error detection on identification numbers (e.g. bank account numbers) which

have been input manually. It is analogous to a binary parity bit used

to check for errors in computer-generated data. It consists of a single

digit (sometimes more than one) computed by an algorithm from the

other digits (or letters) in the sequence input.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 78: Check Digit

Check digit

1 With a check digit, one can detect simple errors in the input of a series of characters (usually digits) such as

a single mistyped digit or some permutations of two successive

digits.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 79: Check Digit

Check digit - Design

1 Check digit algorithms are generally designed to capture human

transcription errors. In order of complexity, these include the

following:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 80: Check Digit

Check digit - Design

1 * single digit errors, such as 1 → 2

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 81: Check Digit

Check digit - Design

1 * transposition errors, such as 12 → 21

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 82: Check Digit

Check digit - Design

1 * twin errors, such as 11 → 22

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 83: Check Digit

Check digit - Design

1 * jump transpositions errors, such as 132 →

231

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 84: Check Digit

Check digit - Design

1 * jump twin errors, such as 131 → 232

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 85: Check Digit

Check digit - Design

1 * phonetic errors, such as 60 → 16 (sixty to sixteen)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 86: Check Digit

Check digit - Design

1 In choosing a system, a high probability of catching errors is

traded off against implementation difficulty; simple check digit systems

are easily understood and implemented by humans but do not

catch as many errors as complex ones, which require sophisticated

programs to implement.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 87: Check Digit

Check digit - Design

1 A desirable feature is that left-padding with zeros should not

change the check digit. This allows variable length digits to be used and

the length to be changed.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 88: Check Digit

Check digit - Design

1 If there is a single check digit added to the original number, the system

will not always capture multiple errors, such as two replacement

errors (12 → 34) though, typically, double errors will be caught 90% of the time (both changes would need to change the output by offsetting

amounts).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 89: Check Digit

Check digit - Design

1 A very simple check digit method would be to take the sum of all digits

(digital root|digital sum) modulo operation|modulo 10. This would

catch any single-digit error, as such an error would always change the

sum, but does not catch any transposition errors (switching two

digits) as re-ordering does not change the sum.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 90: Check Digit

Check digit - Design

1 A slightly more complex method is to take the weighted sum of the digits, modulo 10, with different weights for

each number position.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 91: Check Digit

Check digit - Design

1 To illustrate this, for example if the weights for a four digit number were

5, 3, 2, 7 and the number to be coded was 4871, then one would

take 5×4 + 3×8 + 2×7 + 7×1 = 65, i.e. 5 modulo 10, and the check digit

would be 5, giving 48715.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 92: Check Digit

Check digit - Design

1 Using different weights on neighboring numbers means that most transpositions change the

check digit; however, because all weights differ by an even number,

this does not catch transpositions of two digits that differ by 5, (0 and 5, 1

and 6, 2 and 7, 3 and 8, 4 and 9), since the 2 and 5 multiply to yield

10.https://store.theartofservice.com/the-check-digit-toolkit.html

Page 93: Check Digit

Check digit - Design

1 The code instead uses modulo 11, which is prime, and all the number

positions have different weights 1,2,\dots,10. This system thus detects all

single digit substitution and transposition errors (including jump

transpositions), but at the cost of the check digit possibly being 10,

represented by X. (An alternative is simply to avoid using the serial

numbers which result in an X check digit.) instead uses the GS1

algorithm used in EAN numbers.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 94: Check Digit

Check digit - Design

1 To reduce this failure rate, it is necessary to use more than one

check digit (for example, the modulo 97 check referred to below, which

uses two check digits - for the algorithm, see International Bank Account Number) and/or to use a wider range of characters in the

check digit, for example letters plus numbers.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 95: Check Digit

Check digit - UPC

1 The final digit of a Universal Product Code is a check digit computed as follows:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 96: Check Digit

Check digit - UPC

1 # Add the digits (up to but not including the check digit) in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 97: Check Digit

Check digit - UPC

1 # Add the digits (up to but not including the check digit) in the

even-numbered positions (second, fourth, sixth, etc.) to the result.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 98: Check Digit

Check digit - UPC

1 # Take the remainder of the result divided by 10 (modulo operation)

and subtract this from 10 to derive the check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 99: Check Digit

Check digit - UPC

1 For instance, the UPC-A barcode for a box of tissues is 036000241457. The last digit is the check digit 7, and if the other numbers are correct then

the check digit calculation must produce 7.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 100: Check Digit

Check digit - UPC

1 # Add the odd number digits:

0+6+0+2+1+5 = 14

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 101: Check Digit

Check digit - UPC

1 # To calculate the check digit, take the remainder of (53 / 10), which is also known as (53 modulo 10), and

subtract from 10. Therefore, the check digit value is 7.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 102: Check Digit

Check digit - UPC

1 Another example: to calculate the check digit for the following food item 01010101010.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 103: Check Digit

Check digit - UPC

1 # To calculate the check digit, take the remainder of (5 / 10), which is also known as (5 modulo 10), and

subtract from 10 i.e. (10 - 5 modulo 10) = 5. Therefore, the check digit

value is 5.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 104: Check Digit

Check digit - UPC

1 # If the remainder is 0, subtracting from 10 would give 10. In that case, use 0 as the

check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 105: Check Digit

Check digit - ISBN 10

1 The digit the farthest to the right (which is multiplied by 1) is the

check digit, chosen to make the sum correct

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 106: Check Digit

Check digit - ISBN 10

1 While this may seem more complicated than the first scheme, it can be validated simply

by adding all the products together then dividing by 11. The sum can be computed without any multiplications by initializing

two variables, t and sum, to 0 and repeatedly performing t = t + digit; sum =

sum + t; (which can be expressed in C (programming language)|C as sum += t +=

digit;). If the final sum is a multiple of 11, the ISBN is valid.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 107: Check Digit

Check digit - ISBN 13

1 ISBN 13 (in use January 2007) is equal to the EAN-13 code found underneath a book's barcode. Its check digit is generated the same

way as the UPC except that the even digits are multiplied by 3 instead of

the odd digits.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 108: Check Digit

Check digit - EAN (GLN,GTIN, EAN numbers administered by GS1)

1 EAN (European Article Number) check digits (administered by GS1) are calculated by summing the odd position numbers and multiplying by 3 and then by adding the sum of the even position numbers. Numbers are examined going from right to left, so the first odd position is the last digit

in the code. The final digit of the result is subtracted from 10 to

calculate the check digit (or left as-is if already zero).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 109: Check Digit

Check digit - EAN (GLN,GTIN, EAN numbers administered by GS1)

1 A GS1 check digit calculator and detailed documentation is online at GS1's website.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 110: Check Digit

Check digit - EAN (GLN,GTIN, EAN numbers administered by GS1)

1 Another official calculator page shows that the mechanism for GTIN-13 is the same for Global Location

Number/GLN.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 111: Check Digit

Check digit - International

1 * The International SEDOL number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 112: Check Digit

Check digit - International

1 * The final digit of an ISSN code or IMO

Number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 113: Check Digit

Check digit - International

1 * The International Securities

Identifying Number (ISIN).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 114: Check Digit

Check digit - International

1 * The International CAS registry

number's final digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 115: Check Digit

Check digit - International

1 * Modulo 10 check digits in credit card account numbers, calculated by the Luhn

algorithm.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 116: Check Digit

Check digit - International

1 **Also used in the Norwegian KID (customer identification number)

numbers used in bank giros (credit transfer).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 117: Check Digit

Check digit - International

1 * Last check digit in EAN/UPC serialisation of Global Trade

Identification Number (GTIN). It applies to GTIN-8, GTIN-12, GTIN-13

and GTIN-14.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 118: Check Digit

Check digit - International

1 * The final digit of a Data Universal Numbering System|DUNS number

(though this is scheduled to change, such as that the final digit will be chosen freely in new allocations, rather than being a check digit).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 119: Check Digit

Check digit - International

1 * The third and fourth digits in an International Bank Account Number (Modulo

97 check).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 120: Check Digit

Check digit - International

1 * The final character encoded in a magnetic stripe card is a computed

Longitudinal redundancy check.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 121: Check Digit

Check digit - In the USA

1 * The tenth digit of the National Provider Identifier for the US healthcare industry.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 122: Check Digit

Check digit - In the USA

1 * The North American CUSIP number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 123: Check Digit

Check digit - In the USA

1 * The final (ninth) digit of the routing transit number, a bank code used in the United

States.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 124: Check Digit

Check digit - In the USA

1 * The ninth digit of a Vehicle identification number|Vehicle Identification Number (VIN).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 125: Check Digit

Check digit - In the USA

1 * Mayo Clinic patient identification numbers used in Arizona and Florida

include a trailing check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 126: Check Digit

Check digit - In Central America

1 * The Guatemalan Tax Number (NIT - Número de Identificación Tributaria) based on modulo operator|modulo

11.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 127: Check Digit

Check digit - In Eurasia

1 * The Spanish fiscal identification number (número de identificación fiscal, NIF), (based on modulo 23).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 128: Check Digit

Check digit - In Eurasia

1 * The ninth digit of an Israeli Teudat Zehut (Identity Card) number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 129: Check Digit

Check digit - In Eurasia

1 * The 13th digit of the Serbian and SFRY|Former Yugoslav Unique Master

Citizen Number|Unique Master Citizen Number (JMBG).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 130: Check Digit

Check digit - In Eurasia

1 * The last two digits of the 11-digit

Turkish Identification Number ().

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 131: Check Digit

Check digit - In Eurasia

1 * The ninth character in the 14-character European Union|EU cattle

passport number (cycles from 1 to 7: see British Cattle Movement

Service#Ear tag number|British Cattle Movement Service).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 132: Check Digit

Check digit - In Eurasia

1 * The ninth digit in an Icelandic

Kennitala (national ID number).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 133: Check Digit

Check digit - In Eurasia

1 * Modulo 97 check digits in a Belgium|Belgian and Serbian bank account numbers.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 134: Check Digit

Check digit - In Eurasia

1 * The ninth digit in a Hungary|Hungarian TAJ number (social insurance number).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 135: Check Digit

Check digit - In Eurasia

1 * For the residents of India, the unique identity number named AADHAAR#Salient features of

AADHAAR|Aadhaar has a trailing 12th digit that is calculated with the

Verhoeff algorithm.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 136: Check Digit

Check digit - In Eurasia

1 * The Intellectual Property Office of Singapore|Intellectual Property Office of Singapore (IPOS) has confirmed a new format for application numbers of registrable Intellectual Property (IP, e.g., Trademark|trade marks, patents, Industrial design right|

registered designs). It will include a check character calculated with the

Damm algorithm.https://store.theartofservice.com/the-check-digit-toolkit.html

Page 137: Check Digit

Check digit - In Oceania

1 * The Australian Tax File Number (based on modulo operator|

modulo 11).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 138: Check Digit

Check digit - In Oceania

1 * The seventh character of a New Zealand NHI

Number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 139: Check Digit

Check digit - In Oceania

1 * The last digit in a Locomotives of New Zealand|New Zealand

locomotive's Traffic Monitoring System (TMS) number.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 140: Check Digit

Check digit - Algorithms

1 Notable algorithms include:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 141: Check Digit

Luhn algorithm - Verification of the check digit

1 digits = digits_of(card_numb

er)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 142: Check Digit

Luhn algorithm - Calculation of the check digit

1 The algorithm above checks the validity of an input with a check digit. Calculating the check digit requires

only a slight adaptation of the algorithm—namely:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 143: Check Digit

Luhn algorithm - Calculation of the check digit

1 # Append a zero check digit to the partial number and

calculate checksum

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 144: Check Digit

ISBN - ISBN-10 check digits

1 The 2001 edition of the official manual of the [http://www.isbn-

international.org/ International ISBN Agency] says that the ISBN-10 check

digit– which is the last digit of the ten-digit ISBN– must range from 0 to 10 (the symbol X is used for 10), and must be such that the sum of all the

ten digits, each multiplied by its (integer) weight, descending from 10 to 1, is a multiple of 11 (number)|11.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 145: Check Digit

ISBN - ISBN-10 check digits

1 The two most common errors in handling an ISBN (e.g., typing or writing it) are a single

altered digit or the transposition of adjacent digits. It can be mathematical proof|proved

that all possible valid ISBN-10's have at least two digits different from each other. It can

also be proved that there are no pairs of valid ISBN-10's with eight identical digits and two

transposed digits. (These are true only because the ISBN is less than 11 digits long,

and because 11 is a prime number.)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 146: Check Digit

ISBN - ISBN-10 check digits

1 The ISBN check digit method therefore ensures that it will always be possible to detect these two most

common types of error, i.e

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 147: Check Digit

ISBN - ISBN-10 check digit calculation

1 The resulting remainder, plus the check digit, must equal 11; therefore,

the check digit is (11 minus the remainder of the sum of the products

modulo 11) modulo 11

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 148: Check Digit

ISBN - ISBN-10 check digit calculation

1 The value x_ required to satisfy this condition might be 10; if so, an 'X' should be used.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 149: Check Digit

ISBN - ISBN-13 check digit calculation

1 The 2005 edition of the International ISBN Agency's official manual

describes how the 13-digit ISBN check digit is calculated. The ISBN-13 check digit, which is the last digit of

the ISBN, must range from 0 to 9 and must be such that the sum of all the thirteen digits, each multiplied by its (integer) weight, alternating between 1 and 3, is a multiple of 10 (number)|

10.https://store.theartofservice.com/the-check-digit-toolkit.html

Page 150: Check Digit

ISBN - ISBN-13 check digit calculation

1 The ISBN-10 formula uses the prime number|prime modulus 11 which

avoids this blind spot, but requires more than the digits 0-9 to express

the check digit.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 151: Check Digit

Routing transit number - Check digit

1 The ninth, check digit provides a checksum test using a position-

weighted sum of each of the digits. High-speed check-sorting equipment will typically verify the checksum and

if it fails, route the item to a reject pocket for manual examination,

repair, and re-sorting. Mis-routings to an incorrect bank are thus greatly

reduced.https://store.theartofservice.com/the-check-digit-toolkit.html

Page 152: Check Digit

Routing transit number - Check digit

1 : (Modulo operation|Mod or modulo is the

remainder of a division operation.)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 153: Check Digit

Routing transit number - Check digit

1 In terms of weights, this is 371 371 371

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 154: Check Digit

Routing transit number - Check digit

1 As an example, consider 111000025 (which is a valid routing number of

Bank of America in Virginia). Applying the formula, we get:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 155: Check Digit

Routing transit number - Check digit

1 The following formula can be used to generate the ninth digit in the checksum:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 156: Check Digit

Routing transit number - Check digit

1 This is just moving all terms other than d_9 to the right hand side of the

equation, which inverts the coefficients with respect to 10 (3 \

mapsto (10-3) = 7; 7 \mapsto (10-7) = 3; 1 \mapsto (10-1) = 9).

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 157: Check Digit

Routing transit number - Check digit

1 Following the above example for the Bank of America routing number 111000025,

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 158: Check Digit

Routing transit number - Check digit

1 This checksum is very easy to represent in computer programming

languages. The following Python (programming language)|Python example will print True when the

checksum is valid:

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 159: Check Digit

Damm algorithm - Validating a number against the included check digit

1 #Set up an interim digit and initialize it

to 0.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 160: Check Digit

Damm algorithm - Validating a number against the included check digit

1 #Process the number digit by digit: Use the number's digit as column index and the interim digit as row

index, take the table entry and replace the interim digit with it.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 161: Check Digit

Damm algorithm - Validating a number against the included check digit

1 #The number is valid if and only if the resulting interim digit has the value of 0.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 162: Check Digit

Damm algorithm - Calculating the check digit

1 The resulting interim digit is '4'. This is the calculated check digit. We

append it to the number and obtain '5724'.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 163: Check Digit

UPC code - Check digits

1 # Adding the odd-numbered digits (0+6+0+2+1+5 = 14)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 164: Check Digit

UPC code - Check digits

1 # Calculating modulo ten (58mod10 = 8)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 165: Check Digit

UPC code - Check digits

1 # Subtracting from ten (10minus;8 = 2)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 166: Check Digit

Base 11 - ISBN check digit

1 The check digit for ISBN|ISBN-10 is found as the result of taking modular

arithmetic|modulo 11. Since this could give 11 possible results, the

digit X, not A, is used in place of 10. Remember that X (disambiguation)|X is the Roman numeral for ten. (The

newer ISBN-13 standard uses modulo 10, so no extra digits are required.)

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 167: Check Digit

Code 128 - Check digit calculation

1 The remainder of the division is the check digit's 'value' which is then

converted into a character (following the instructions given Code

128#Conversion to char|below) and appended to the end of the barcode.

https://store.theartofservice.com/the-check-digit-toolkit.html

Page 168: Check Digit

Code 128 - Calculating check digit with multiple variants

1 As Code 128 allows multiple variants, as well as switching between variants within a single barcode, the absolute Code 128 value of a character is completely independent of its value within a given variant. For instance

the Variant C value 33 and the Variant B value A are both considered to be a Code 128 value of 33, and the check digit would

be computed based on the value of 33 times the character's position within the

barcode.https://store.theartofservice.com/the-check-digit-toolkit.html