Decode UPC Bar Codes


So let’s say you would like to decode the actual bars in the bar code and map them to numbers. This is something that will make you cross-eyed, but it can be done.

First of all, look at any 12-digit bar code. It is made up of black bars and white spaces between the bars. Assume that the thinnest bar or space that you see (for example, the first bar on the left) can be called “one unit wide.” The bars and spaces can therefore be seen to have proportional widths of one, two, three or four units. If you look at any bar code you can see examples of these four widths.

The start of any bar code is “1-1-1.” That is, starting at the left you find a one-unit-wide black bar followed by a one-unit-wide white space followed by a one-unit-wide black bar (bar-space-bar). Following the start code, the digits are encoded like this:

     0 = 3-2-1-1
     1 = 2-2-2-1
     2 = 2-1-2-2
     3 = 1-4-1-1
     4 = 1-1-3-2
     5 = 1-2-3-1
     6 = 1-1-1-4
     7 = 1-3-1-2
     8 = 1-2-1-3
     9 = 3-1-1-2



(Something to notice: All of these encodings seem to add up to 7.)

So let’s take this barcode as an example:

The code embedded in the bars is 043000181706:

  • The bar code starts with the standard start code of 1-1-1 (bar-space-bar).
  • The zero is 3-2-1-1 (space-bar-space-bar).
  • The four is 1-1-3-2 (space-bar-space-bar).
  • The three is 1-4-1-1 (space-bar-space-bar).
  • The next three zeros are 3-2-1-1 (space-bar-space-bar).
  • In the middle there is a standard 1-1-1-1-1 (space-bar-space-bar-space), which is important because it means the numbers on the right are optically inverted!
  • The one is 2-2-2-1 (bar-space-bar-space).
  • The eight is 1-2-1-3 (bar-space-bar-space).
  • The one is 2-2-2-1 (bar-space-bar-space).
  • The seven is 1-3-1-2 (bar-space-bar-space).
  • The zero is 3-2-1-1 (bar-space-bar-space).
  • The six is 1-1-1-4 (bar-space-bar-space).
  • The stop character is a 1-1-1 (bar-space-bar).

Have fun decoding those 12-digit bar codes!

For more information on bar codes and related topics, check out the links at How stuff works


Tags: , , ,

One Response to “Decode UPC Bar Codes”

  1. writemeg Says:

    Trying to read this entry made my brain hurt! No math allowed on cutthroatkids!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: