UPC Barcodes

barcode-640522710850A barcode is a visual representation of data that can easily be read by an optical barcode scanner/reader. Barcodes are used to facilitate and speed up the identification of different types of products. Using a barcode reader speed up the input/data entry process and and is a more reliable method generating less data entry errors than when a product code is entered manually.

There are different types/formats of barcodes such as ISBN barcodes used to identify books/publications or UPC (Universal Product Codes) or EAN (European Article Number) barcodes to uniquely identify products/trade items.

You can visit this wikipedia page to find out a about a range of linear barcodes (1D) and matrix barcodes (2D) such as QR codes.

UPC Encoding

Let’s focus on UPC barcodes. UPC barcodes are widely used in America, Europe, Australia, New Zealand, and other countries for tracking trade items in stores. A UPC barcode is a linear barcode consisting of a series of black and white stripes of different thickness. They are used to encode 12 numerical digits in two groups/segments of 6 digits: the left segment and the right segments.

A UPC barcode is delimited using guards: specific patterns that appear at the start, at the end and also in the middle of the barcode to separate the left and right segment:
upc-barcode-anatomy

With UPC barcodes, the first and last digits are often displayed before and after the left and right hand side guards of the barcode (even though the stripes representing these digits are still within the guards patterns):
UPC-barcode-digits-position

Each numerical digit is encoded using a specific pattern. However the patterns used are different on the left and right segments. This feature is necessary to ensure that barcode readers can read a barcode in both directions (in case a barcode is presented upside down). In fact the patterns used on the right segments for each digit are the exact opposite to the patterns used for the digits on the left segment. Each pattern is seven stripes wide:
upc-barcode-digits

Decoding a barcode

Use the information provided above to decode the following barcodes and check your UPC codes using barcodespider.com to identify the corresponding products.

# Barcode Product UPC?
#1 Raspberry Pi Model 3B
#2 32GB SD Card
#3 Optical Cordless Mouse

Barcode Generator

Check digits

The last digit of a UPC-A barcode is the check digit. A check digit is used to minimise the risk of errors when scanning a barcode. A check digit calculation is used to confirm that a barcode being scanned is valid or not. You can read more about check digit validation on this blog post.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.4 / 5. Vote count: 18

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!