The UPC-E barcode format is a compressed form of the UPC-A format and is used where space is at a premium. The UPC-E format also require that there are at least 5 0’s in a group in the barcode, so that it can be compressed.
Before we shorten the barcode, we need to enter a full 11 digit UPC-A barcode (excluding the parity digit), and then calculate the parity digit as per the UPC-A barcode.
We first need add up the 11 digits of the barcode with the weighting applied. The weighting is the same as the EAN-13 and UPC-A weighting, where the weighting of each digit which is in an odd-numbered position is 1 and for even-numbered positions, the weighting is 3. To find the sum, we need to multiply each digit by its weighting before adding it together.
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).
Now that we have an 12 digit number, we need to shorten it to an 8 digit number.
The rules for this are quite simple.
The manufacturer portion of the number is the first 5 digits excluding the first digit of the barcode. The product portion is the subsequent 5 digits.
If the last 3 manufacturer digits are 100, 200 or 000, then the shortened for is made up of the first digit, the first two digits of the manufacturer, the last 3 digits of the product, the third digit of the manufacturer and finally the parity.
Otherwise, if the last two digits of the manufacturer is 00, then the barcode is made up of first digit, the first three digits of the manufacturer, the last 2 digits of the product, the number 3, and finally the parity.
Then, if the last digit of the manufacturer is 0, the barcode is made up of first digit, the first four digits of the manufacturer, the last digit of the product, the number 4, and finally the parity.
We can now use this number for the rest of the calculation
We do not split up this format, and only have with a guard bar at the beginning and end of the barcode. The left guard bars are encoded as 101, while the right guard bar is 010101.
The first digit of the barcode determines the parity set to use. The encodings are split up by odd and even encodings, which is determined by the parity bit. This is found by choosing the correct parity set encodings, and then finding the parity bit string for the parity we calculated earlier, and then returning the bit value at the position in the string for the digit we wish to encode.
Digit</stromg></td>
Set 0
Set 1
</tr>
0
000111
111000
1
001011
110100
2
001101
110010
3
001110
110001
4
010011
101100
5
011001
100110
6
011100
100011
7
010101
101010
8
010110
101001
9
011010
100101
</table>
Once we have the parity bit, we then choose the odd or even encoding accordingly, for each digit. Only 6 digits are explicitly encoded, since the first and last digits are used to calculate the parity bit, so are not needed to be encoded directly.
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_