1

I'm looking for the correct solution to decode a Code 3 of 9 barcode format. What I found on wikipedia stated the following:

Each character is composed of nine elements: five bars and four spaces. Three of the nine elements in each character are wide (binary value 1), and six elements are narrow (binary value 0). - Wikipedia

My questions are as follows:

  1. By "elements" does that mean one bar?
  2. Does the binary output of one Code 39 digit have 9 or 12 binary digits?

My assumptions are as follows:

  1. There is not a check digit
  2. We are not dealing with full ASCII Code 39

Let's say we have the following barcode:

enter image description here

Let's focus on the start character *. I can think of three different ways to potentially decode this character to binary:

  1. Assumption that a black bar is 1 and a white bar is 0
    • 1001 0110 1101 – 12 bits
  2. Assumption that a thin line is a 0 and a thick line is 1
    • 0100 1010 1 – 9 bits
  3. Assumption that a thin line is a 0 and a thick line is 11
    • 0110 0110 1101 – 12 bits

Which decoding method is correct? If none of them, then please let me know what the correct method is.

2 Answers 2

1

I use 16 bits to represent a '9 element' code 39 character. For example an asterisk ('*') looks like this '1000101110111010' in my software. By elements, they mean bars and spaces, alternating. You may find difficulty reading codes assuming that the wide to narrow ratio is 2:1 for both bars and spaces.

Sign up to request clarification or add additional context in comments.

3 Comments

The software I developed prints the barcodes onto web pages, so I just use a manually derived lookup table:
That's literally what I've been looking for!
0

None of them.

With code 3 of 9, the code itself consists of nine "elements" - five bars and four spaces plus an extra space as intercharacter gap. The bar or space "element" may be narrow or wide; 3 are wide, 6 are narrow.The "tenth" element (intercharacter space) is always narrow (IIRC). The code alternates bar-space-bar-space... and the coding is nWWnnWnnnN for instance. Convert this to binary and you have a 9-bit number (ignoring the intercharacter space N) which bears no relation to ASCII. Each of these numbers is then mapped to ASCII by the reader.

Some patterns are reserved for orientation information so that the correct result can be determined if the barcode is read "upside-down", otherwise the string read would appear garbled since the previous string nWWnnWnnnN would be read as NnnnWnnWWnwhich is an entirely different character.

It is optional to have a Mod-43 check-digit.

2 Comments

So the 9-bit binary sequence would be what? If you have a barcode format send out of a device via serial it has to be sent a series of high and low voltages (binary). Continuing to ponder my question, what is the correct binary representation of * encoded in Code 39?
The * means code start/end sequence (for orientation.) A * actually encoded within the data would produce a different sequence of elements. The code 000000111 000001110 000001101 ... 111000000 is mapped to an ASCII character by the reader's firmware and appears as output in ASCII - or theoretically EBCDIC or any other code you fancy. It would be theoretically possible to output the code as "code 39" - directly as-read, but for some strange reaon, people seem to prefer to deal with ASCII.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.