x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1119

# Calculate an ISBN checksum?

Hello Everyone,

I am trying to automate a few things here at the office for everyone. One of my projects is to create a simple program (very simple) that calculates the checksum or check digit of an ISBN number.

For example:
If you had an ISBN number of 157521030, the checksum would be 4. I've seen examples to verify the checksum, and I've seen the mathmatical equation, but I was wondering if anyone had a simple function or routine that does this? Perhaps a pointer to one that does?

Any help or guidance would be greatly appreciated.

Sincerely,

Sandra Wallace
sandra_wallace@yahoo.com

0
sandra_wallace
• 2
1 Solution

Author Commented:
Edited text of question
0

Commented:
This function will calculate the ISBN checksum:

function ISBNCheckDigit(ISBN :string):char;
var
CheckSum : integer;
ModValue : Integer;

begin
CheckSum := 10 * strtoint(ISBN[1]);
CheckSum := checksum + 9 * strtoint(ISBN[3]);
CheckSum := checksum + 8 * strtoint(ISBN[4]);
CheckSum := checksum + 7 * strtoint(ISBN[6]);
CheckSum := checksum + 6 * strtoint(ISBN[7]);
CheckSum := checksum + 5 * strtoint(ISBN[8]);
CheckSum := checksum + 4 * strtoint(ISBN[9]);
CheckSum := checksum + 3 * strtoint(ISBN[10]);
CheckSum := checksum + 2 * strtoint(ISBN[11]);

ModValue := Checksum mod 11;
if ModValue < 10 then
result := chr(asc('0') + ModValue - 1)
else
result := 'X';
end;

Cheers,

Raymond.
0

Commented:
Oops,  this line

result := chr(asc('0') + ModValue - 1)

result := chr(ord('0') + ModValue - 1)

Cheers,

Raymond.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.