How do I calculate a Code EAN checksum?

Code EAN uses a simple Modulo 10 checksum scheme. The 12 (or 7 in case of EAN 8) digits of the message are multiplied with '1' and '3' (alternating). The products are then added up and integer divided by ten. The remainder (modulo) of the division is subtracted from '10', the result is the check digit.

Here is a simplified EAN 13 checksum function in C, source code:

int _checksum_ean13(char *data)
{
  int sum = 0;
  int i;
  
  for(i=11;i>=0;i--)
  {
     int digit = *(data + i);
     if(i & 0x01)
       sum += digit * 3;
     else
       sum += digit;
  }
  int mod = sum % 10;
  if(mod != 0)
     return 10 - mod;
  return 0;
}

Note: All our applications and developer components and libraries have automatic checksum calculation for Code EAN 8 / 13 and ISBN 10 / 13.

Developers: Make sure to see our .NET barcode SDK!