Task

Validate the check digit of an ISBN-13 code:

   Multiply every other digit by  3.
   Add these numbers and the other digits.
   Take the remainder of this number after division by  10.
   If it is  0,   the ISBN-13 check digit is correct.


Use the following codes for testing:

   978-1734314502       (good)
   978-1734314509         (bad)
   978-1788399081       (good)
   978-1788399083         (bad)


Show output here, on this page



See also

   for details:   13-digit ISBN method of validation.       (installs cookies.)


Macro TestISBN13(X)  
  Print(X) 
  If IsISBN13(X) : PrintN(" good") : Else : PrintN(" bad") : EndIf  
EndMacro
 
Procedure.b IsISBN13(ISBN13.s)  
  ISBN13=Left(ISBN13,3)+Mid(ISBN13,5)  
  If IsNAN(Val(ISBN13)) Or Len(ISBN13)<>13 : ProcedureReturn #False : EndIf
  Dim ISBN.s{1}(12) : PokeS(@ISBN(),ISBN13)  
  For i=0 To 11 Step 2 : sum+Val(ISBN(i))+Val(ISBN(i+1))*3 : Next
  sum+Val(ISBN(12))
  ProcedureReturn Bool(sum%10=0)
EndProcedure
 
If OpenConsole()
  TestISBN13("978-1734314502")
  TestISBN13("978-1734314509")
  TestISBN13("978-1788399081")
  TestISBN13("978-1788399083")
  Input()
EndIf