Before I re-invent the wheel, does anybody have any code lying
around that converts ISBN-10 to ISBN-13?
Thanks,
Keith
IMHO you need:
- the ISBN prefix: 978
- the first 9 digits of the ISBN-10
- the newly calculated EAN-13 check digit.
Here is code for the check digit calculation:
# Find the EAN 8/13/SSCC check digit
proc CheckEAN In {
set Sum 0
set Pos [string length $In]
set fWeight 0
while { $Pos > 0 } {
incr Pos -1
set Num [string index $In $Pos]
incr Sum $Num
if {$fWeight} {
set fWeight 0
} else {
incr Sum $Num
incr Sum $Num
set fWeight 1
}
}
return [expr { ( 10 - ( $Sum % 10 ) ) % 10 } ]
}
Hope this helps,
Harald
> Hi,
>
> Before I re-invent the wheel, does anybody have any code lying
> around that converts ISBN-10 to ISBN-13?
Look into Tcllib, the snit validation types I made (1). The isbn code
also have a "13of" method which does the 10->13 conversion, as part of
isbn canonicalization.
(1) subdirectory modules/valtype
The code of the method
typemethod 13of {value} {
if {![regexp {^[0-9]+[Xx]?$} $value]} {
badchar ISBN "ISBN-10 number, expected only digits, and possibly 'X' or 'x' as checkdigit"
} elseif {[string length $value] != 10} {
badlength ISBN 10 "ISBN-10 number"
}
# Strip the -10 check digit, prefix the remainder with the
# bookland country code and recalculate the check digit, via
# -13.
set n 978[string range $value 0 end-1]
return $n[$type checkdigit $n]
}
HTH.
> Thanks,
> Keith
--
So long,
Andreas Kupries <akup...@shaw.ca>
<http://www.purl.org/NET/akupries/>
Developer @ <http://www.activestate.com/>
-------------------------------------------------------------------------------