How do I calculate a Code 39 check character?

Code 39 is mostly used without a check digit. However, in environments where the code may be damaged, using a check character may be advised to prevent false readings.

Each character of the Code 39 character set has a numeric value between '0' and '42'. To calculate the checksum the values of all characters (without the start character) are summed up. The result is integer divided by 43, the remainder gives the numeric value of the check character (that's a basic Modulo 43 operation). Note that any character of the Code 39 character set can be a check digit, even letters or special characters.

Here is a checksum function in C:

unsigned char calculateChecksum(unsigned char *data, int len)
  int sum = 0;
  for(int i = 0;i<len;i++)
    sum += valueFromCharacter(*(data + i));
  return characterFromValue(sum % 43);

The valueFromCharacter function simply gets the numeric value of the character from a table like the following:

unsigned char c39_cw[43] =
  'U','V','W','X','Y','Z','-','.',' ','$',

The characterFromValue performs the reverse task.

Note: All our applications that support Code 39 have automatic checksum calculation for Code 39.

Please see also our page about Code 39 which has more information on this barcode as well as a Code 39 Extended code table.