PostNet (3 of 5)
Home >
Barcode Basics >
Different Types of
Barcodes > PostNet
The PostNet barcode is
used by the United States Postal Service to automatically sort mail. The PostNet code
consists of evenly spaced bars of two different heights. Each character is represented by
five bars, two tall and three short. The character set includes the digits 0 through 9.
The code begins and ends with a tall bar ('frame bar'), and may contain a 5-digit ZIP
code, a 9-digit ZIP+4 code, or an 11-digit Delivery Point Code. A Modulo 10 check digit
('correction character') is inserted after the ZIP code and before the ending frame bar.
The check digit is calculated on the content of each ZIP code. The check digit is
simply the number that, when added to the sum of the digits in the ZIP code, will produce
an even multiple of 10.
Here is some sample 'C' code that will calculate the checksum. This function will
work with any length of zip code (it will not generate an error if the zip code is an
incorrect length), and it will automatically skip over any embedded dashes or other
non-numeric characters. Note that dashes have to be removed before printing the
barcode:
int checksum(char *zipcode)
{
int tot;
char *cp;
tot = 0;
cp = zipcode;
while (*cp != 0) {
if (*cp >= '0' && *cp <= '9')
tot += *cp - '0';
cp++;
}
return(10 - (tot % 10));
}
Here is a routine for FileMaker Pro. This function operates on a 9-digit zip code
and assumes that there are no embedded dashes. CALCTOT adds up the digits and
CHECKSUM calculates the check digit:
ZIP Text
CALCTOT Calculation(Number) = TextToNum(Left(ZIP,1)) + TextToNum(Middle(ZIP,2,1))
+ TextToNum(Middle(ZIP,3,1)) + TextToNum(Middle(ZIP,4,1)) +
TextToNum(Middle(ZIP,5,1)) + TextToNum(Middle(ZIP,6,1)) + TextToNum(Middle(ZIP,7,1)) +
TextToNum(Middle(ZIP,8,1)) + TextToNum(Middle(ZIP,9,1))
CHECKSUM Calculation(Number) = 10 - MOD(CALCTOT,10)
See also:
AppNote 003:
Calculating the PostNet Barcode Checksum in Access Basic