[barcode] Different strings give same barcode

Alessandro Rubini rubini@gnudd.com
Thu Jun 2 23:09:48 CEST 2005


Hello.
Please note that UPC-E is a strange beast. 

> $  barcode -En  -e upc-e -b 058764

> $ barcode -En  -e upc-e -b 058706

If I remove the "-n", I find the string is the same (as expected).
It is "0 058764 8". Is that what you want?

>From the documentation I find:

     For
     UPC-E, 6 digit are considered to be the middle part of the code, a
     leading 0 is assumed and the checksum is added; 7 digits are
     either considered the initial part (leading digit 0 or 1, checksum
     missing) or the final part (checksum specified, leading 0
     assumed); 8 digits are considered to be the complete code, with
     leading 0 or 1 and checksum. 

So your 6-digits codes are interpreted as the middle part (that's
why you get the leading 0 and the trailing checksum added). Now,
why does the second number become the first?

>From ean.c, I find that upc-e is converted to upc-a (upc_e_to_a),
since the E format is just a condensed version of upc-a. There,
you see that the last digit (4 or 6 in your examples) selects
how compression is done. A 4 means you have 4 manufacturer digit
and 1 product digit (here: 0587 and 6), while a digit in 5..9
means you have 5 manufacturer digits and the product (5..9).
Here this means 05870 and 6.

But the checksum is calculated in the UPC-A representation, which
is then re-condensed to UPC-E. So your two numbers get back to
the same representation.

For this reason, UPC-E shouldn't be used to represent anything else
than official product codes, unfortunately (I think EAN-8 has
the same drawbacks, but I'm not sure and won't check now).  If you want
a compact code without strange side effects, you can use code128

Hope this helps
/alessandro


More information about the barcode mailing list