Updated 2018-05-23 16:05:14 by ak

Silas - 2005.08.18

Suppose you have first 12 digits of EAN-13 barcode. You'll have to calcule the 13th digit, which is the checksum digit. I've done 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
  }

AK: A similar procedure can also be found in EAN-13 generation (ean13_csum).

See also Tcllib EAN 13 Validation and related packages.