Version 0 of EAN-13 checksum

Updated 2005-08-18 18:02:09

Silas - 2005.08.18

Suppose you have first 12 digits of EAN-13 barcode. You'll have to calcule the 13th digits, which is the checksum digit. I did a little proc that makes it for you:

  proc checksum {first12digits} {
    set total 0

    for {set i 0} {$i < 12} {incr i} {
      set multiplicator [expr ($i % 2 == 0) ? 1 : 3]
      incr total [expr [string index $first12digits $i] * $multiplicator]
    }

    set checksum [expr 10 - ($total % 10)]
    return $checksum
  }

Category barcode