How would the string "CSE370" be encoded in barcode
format?
By The Bit Bashers (Brendan Walker & Jared
Roberts)
As it turns out there are actually several
different barcode formats currently in existence. Therefore, we first must choose
a format appropriate to the string that we want to encode. In addition to this
there are also certain dimensional considerations for the barcode. We must
decide (depending on the bar code format) what the ratio in width is for the
narrow to wide bars, how narrow are the narrow bars, etc. In any case, one of
the simplest alphanumeric barcode formats in use today is called "Code
39" or "Code 3 of 9." Therefore our question now becomes: How do
we encode the string "CSE370" in Code 39?
Code 39 gets its name from that fact that every encoded
character contains exactly nine bars (either black or white) and three bars are
always wide. This implies that there are only two kinds of bars, narrow and
wide ones. Every character is composed of an alternating sequence of black and
white bars, starting and ending with a black bar. I imagine this is done
because a format, which doesn't alternate might be more error prone. Two or
more adjacent black or white bars could be confused for some smaller multiple
of bars if the scanning speed of the bar code is varied. Anyway, the encoded
example character to the left demonstrates all the rules of Code 39. There are
three wide bars (two black and one white) and six narrow bars (three black and
three white). It is also important to note that the sequence begins and ends
with black bars so that there is less confusion about the location of one
encoded character vs. another.
The dimensions of the entire barcode can be calculated once some basic parameters of the barcode are defined. These parameters are: the number of characters in the string (C), the width of the narrow bars (W), ratio of the widths between wide and narrow bars (R), and finally the inter-character gap width between each encoded character (I). The total length (L) of the barcode is expressed as:
L = (C + 2)(3R + 6)W + (C + 1)I
Typical values for each of these
parameters are in unit of mils or thousands of an inch. The smallest width a
narrow bar can be and still be considered standard is 7.5 mils. If the narrow bar
width (W) is less then 20 mils, then the width ratio (R) between wide and
narrow bars must be between 2.0 and 2.2. If the narrow bar width is greater
then or equal to 20 mils, then ratio is between 2.0 and 3.0. The
inter-character gap width (I) is between 1.0 to 5.3 times greater than the
narrow bar width if the narrow bar width is less than 10 mils and between 1.0
to 3.0 times greater (or 53 mils, whatever is bigger) if the narrow bar width
is greater then or equal 10 mils. Typically the inter-character width is the
same as narrow bar width. The height of the barcode should be 0.15 times that
of its length or 0.25 inches, whatever is greater. It is also important to note
that is possible to go outside these suggested values (for example making the
narrow bar width smaller than 7.5 mils), but you risk making your barcode
unreadable to some or all barcode scanners. Unless of course this is your
intent and you have some custom barcode hardware.
To reduce the chance of scanning errors
all code 39 barcodes use two methods to reduce errors. Code 39 codes begin and
end with an encoded asterisk character to tell the scanner exactly when the
data string begins and ends. These two asterisks are not included in the
character count (C), thus the (C + 2) factor in the length calculation. In
addition to this, an optional checksum character can be added to the end of the
character sting. Each character is associated with a numerical value in the
table below. The checksum is the sum of all the character's values (with the
exception of the last checksum character) and then modulo 43. If the checksum
is the same as the value of the checksum character then the string was read
error free. In order to do the checksum calculation we have to know in advance
that there is a checksum character; otherwise it's just treated as the last
character in the string. For example, in the encoded “CSE370” string below the
check sum character is mod(12+28+14+3+7+0, 43) = mod (64, 43) = 21 = L.
Bar Code Definition Table
Char. |
Pattern |
Value |
Char. |
Pattern |
Value |
Char. |
Pattern |
Value |
Char. |
Pattern |
Value |
0 |
n n n w w n w n n |
0 |
C |
w n w n n w n n n |
12 |
O |
w n n n w n n w n |
24 |
- |
n w n n n n w n w |
36 |
1 |
w n n w n n n n w |
1 |
D |
n n n n w w n n w |
13 |
P |
n n w n w n n w n |
25 |
. |
w w n n n n w n n |
37 |
2 |
n n w w n n n n w |
2 |
E |
w n n n w w n n n |
14 |
Q |
n n n n n n w w w |
26 |
SP |
n w w n n n w n n |
38 |
3 |
w n w w n n n n n |
3 |
F |
n n w n w w n n n |
15 |
R |
w n n n n n w w n |
27 |
* |
n w n n w n w n n |
N/A |
4 |
n n n w w n n n w |
4 |
G |
n n n n n w w n w |
16 |
S |
n n w n n n w w n |
28 |
$ |
n w n w n w n n n |
39 |
5 |
w n n w w n n n n |
5 |
H |
w n n n n w w n n |
17 |
T |
n n n n w n w w n |
29 |
/ |
n w n w n n n w n |
40 |
6 |
n n w w w n n n n |
6 |
I |
n n w n n w w n n |
18 |
U |
w w n n n n n n w |
30 |
+ |
n w n n n w n w n |
41 |
7 |
n n n w n n w n w |
7 |
J |
n n n n w w w n n |
19 |
V |
n w w n n n n n w |
31 |
% |
n n n w n w n w n |
42 |
8 |
w n n w n n w n n |
8 |
K |
w n n n n n n w w |
20 |
W |
w w w n n n n n n |
32 |
|
|
|
9 |
n n w w n n w n n |
9 |
L |
n n w n n n n w w |
21 |
X |
n w n n w n n n w |
33 |
|
|
|
A |
w n n n n w n n w |
10 |
M |
w n w n n n n w n |
22 |
Y |
w w n n w n n n n |
34 |
|
|
|
B |
n n w n n w n n w |
11 |
N |
n n n n w n n w w |
23 |
Z |
n w w n w n n n n |
35 |
|
|
|
"CSE370" Encoded String
In order to create the above barcode as well as test it we used a few open source tools. To create the barcode a tool called, "GNU Barcode," converts a text string into a postscript file. We then printed out the post script file and used a free bar code scanning tool called a, "CueCat," to rescan the code and verify that it worked. These free scanners use to be available at Radio Shack, but the company that produced them (Digital Convergence) went out of business. The barcode information that comes from the actual CueCat is encrypted, but several decoder programs were written and are freely available on the Internet. A link to one such program is listed below as well as the barcode postscript converter.
References
“Bar Code 39 Specification Page.” http://www.adams1.com/pub/russadam/39code.html, Russ Adams, 09/09/2001.
“Bar Code 39 Specification.” http://www.barcodeman.com/info/c39_1.php3, Altek Instruments Ltd, 05/08/2001.
Utilities
http://ar.linux.it/software/ - barcode - GNU Barcode Post Script Converter
http://www.fluent-access.com/wtpapers/cuecat/cuecat.c - CueCat wand decoder program