UPC-5 is a variation on the UPC-A barcode](/programming/2009/10/barcodes-in-csharp-upca) designed to contain 5 digits of data.
The checksum (or parity) for the UPC-5 format is used only to encode the barcode, and therefore is not coded directly.
Calculating the parity uses the same modulo 10 method as the UPC-A, except that the weightings are different. Odd-numbered positions are weighted 3, while even-numbered positions are weighted 9.
Once we have the weighted sum, we apply a modulo 10 to the weighted sum, which gets the remainder after applying a modulo of 10 to the weighted sum.
The parity is then 10 - (modulo 10 of the weighted sum).
UPC-5 only has a left guard and centre guard (which is places after the third digit), which are encoded as 1011 and 01 respectively.
The 5 digits are then encoded using either odd or even encoding, which is determined by the parity string.
0
00111
1
01011
2
01101
3
01110
4
10011
5
11001
6
11100
7
10101
8
10110
9
11010
The odd and even encodings are the same as the ones for the UPC-E format</p>
Digit
Odd
Even
0
0001101
0100111
1
0011001
0110011
2
0010011
0011011
3
0111101
0100001
4
0100011
0011101
5
0110001
0111001
6
0101111
0000101
7
0111011
0010001
8
0110111
0001001
9
0001011
0010111
The full source code is available at [https://github.com/sjmeunier/barcoder](https://github.com/sjmeunier/barcoder).
_Originally posted on my old blog, Smoky Cogs, on 27 Oct 2009_