Converting ISBN13 to ISBN10
Thursday, January 28th, 2010 -- By ETI need to convert a bunch of isbn numbers from the 13-digit format to the 10-digit format.
Figured out the algorithm, and implemented the following subroutine in PERL. It should be fairly simple to port it to other languages.
sub isbn1310{
my $isbn13=shift;
my @isbn13=split(//,$isbn13);
my $sum = ($isbn13[3] * 10) + (9 * $isbn13[4]) + (8 * $isbn13[5]) + (7 * $isbn13[6]) + (6 * $isbn13[7]) + (5 * $isbn13[8]) +
(4 * $isbn13[9]) + (3 * $isbn13[10]) + (2 * $isbn13[11]);
my $mode = int(($sum / 11) + 1);
my $last = (11 * $mode) - $sum;
if ($last == 10) {
$last = “X”;
} elsif ($last == 11) {
$last = 0;
}
my $isbn10=”$isbn13[3]“.”$isbn13[4]“.”$isbn13[5]“.”$isbn13[6]“.”$isbn13[7]“.”$isbn13[8]“.”$isbn13[9]“.”$isbn13[10]“.”$isbn13[11]“.”$last”;
return $isbn10;
}


