International Standard Book Number - Check Digits - ISBN-13 Check Digit Calculation

ISBN-13 Check Digit Calculation

The 2005 edition of the International ISBN Agency's official manual covering some ISBNs issued from January 2007, describes how the 13-digit ISBN check digit is calculated.

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.

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

s = 9×1 + 7×3 + 8×1 + 0×3 + 3×1 + 0×3 + 6×1 + 4×3 + 0×1 + 6×3 + 1×1 + 5×3 = 9 + 21 + 8 + 0 + 3 + 0 + 6 + 12 + 0 + 18 + 1 + 15 = 93 93 / 10 = 9 remainder 3 10 – 3 = 7

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

Formally, the ISBN-13 check digit calculation is:

This check system – similar to the UPC check digit formula – does not catch all errors of adjacent digit transposition. Specifically, if the difference between two adjacent digits is 5, the check digit will not catch their transposition. For instance, the above example allows this situation with the 6 followed by a 1. The correct order contributes 3×6+1×1 = 19 to the sum; while, if the digits are transposed (1 followed by a 6), the contribution of those two digits will be 3×1+1×6 = 9. However, 19 and 9 are congruent modulo 10, and so produce the same, final result: both ISBNs will have a check digit of 7. 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.

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).

// Java public static boolean isISBN13Valid(String isbn) { int check = 0; for (int i = 0; i < 12; i += 2) { check += Integer.valueOf(isbn.substring(i, i + 1)); } for (int i = 1; i < 12; i += 2) { check += Integer.valueOf(isbn.substring(i, i + 1)) * 3; } check += Integer.valueOf(isbn.substring(12)); return check % 10 == 0; } //JavaScript function isValidISBN13(ISBNumber) { var check, i; ISBNumber = ISBNumber.replace(/-\s/g,''); check = 0; for (i = 0; i < 13; i += 2) { check += +ISBNumber; } for (i = 1; i < 12; i += 2){ check += 3 * +ISBNumber; } return check % 10 === 0; } //PHP function is_isbn_13_valid($n){ $check = 0; for ($i = 0; $i < 13; $i+=2) $check += substr($n, $i, 1); for ($i = 1; $i < 12; $i+=2) $check += 3 * substr($n, $i, 1); return $check % 10 == 0; } # Ruby def isbn_checksum(isbn_string) digits = isbn_string.split(//).map(&:to_i) transformed_digits = digits.each_with_index.map do |digit, digit_index| digit_index.modulo(2).zero? ? digit : digit*3 end sum = transformed_digits.reduce(:+) end def is_valid_isbn13?(isbn13) checksum = isbn_checksum(isbn13) checksum.modulo(10).zero? end def isbn13_checksum_digit(isbn12) checksum = isbn_checksum(isbn12) 10 - checksum.modulo(10) end # Python def is_valid_isbn13(isbn13): total = sum(int(num) * weight for num, weight in zip(isbn13, (1, 3) * 6)) ck = (10 - total) % 10 return ck == int(isbn13) // C/C++ bool is_valid_isbn13(char digits) { int i, check=0; for (i=0; i<13; i+=2) check += digits; for (i=1; i<12; i+=2) check += 3*digits; return check%10==0; }

Read more about this topic:  International Standard Book Number, Check Digits

Famous quotes containing the words check, digit and/or calculation:

    cried as he died, fearing at last the spheres’
    Last sound, the world going out without a breath:
    Too proud to cry, too frail to check the tears,
    And caught between two nights, blindness and death.
    Dylan Thomas (1914–1953)

    Bless my soul, Sir, will you Britons not credit that an American can be a gentleman, & have read the Waverly Novels, tho every digit may have been in the tar-bucket?
    Herman Melville (1819–1891)

    Common sense is the measure of the possible; it is composed of experience and prevision; it is calculation appled to life.
    Henri-Frédéric Amiel (1821–1881)