Chapter 4. Creating Barcode String in your application

Code 39 (also known as USS [4] Code 39, Code 3 of 9) is the first alpha-numeric symbology developed to be used in non-retail environment. It is widely used to code alphanumeric information, such as model numbers etc. It is designed to encode 26 upper case letters A-Z, 10 digits 0-9 and 7 special characters - hyphen (-), period (.), dollar sign ($), forward slash (/), plus sign (+), percent (%) as well as the space character.

Code 39 can have an optional modulo 43 check digit. It also has a variant called code 39 extended or code 39 full ASCII, which is capable of encoding all 128 7-bit characters (ASCII values 0 - 127).

Code39 is a fairly simple symbology. Still, you can not just type the number and format with the font. A code39 barcode string includes additional characters, such as start/stop characters and checksum character. Due to limitations imposed by the font technology, you need to enter another character for space. We'll go through these topics one by one below.

4.1. Character Mappings In Code 39 Fonts

A character in Code 39 fonts is mapped to itself, with exception of space. Since space is reserved for many other purposes, it must remain blank. To print a barcode character that will be scanned as space, use underscore (_) or equal sign (=).

To print start/stop characters, use asterisk (*). You can also use left square bracket [ and right square bracket ] to produce them. The only difference between square brackets and asterisk is that the latter has human readable character * beneath the barcode in a human readable font. In non-human-readable fonts, they print identical patterns.

4.2. Normal Code39

To create barcode string for a normal code 39 without check digit, enclose your data with either asterisks or square brackets. For example, both *PN99018* and [PN99018] produce code 39 barcodes with text PN99018 encoded.

4.3. Modulo 43 Checksum

Some applications, such as HIBC and LOGMARS, require a modulo 43 Check character at the end of the barcode (just before the stop character). The scanners must be configured with the checksum verification turned on in order to use the feature. The design of the checksum is to guard the data integrity. The scanner calculates the checksum at the time of scan, if it does not match the one in the barcode, the scanner assumes that some portion of the barcode was misprinted or misread and rejects the barcode.

To create barcode string with check digit, first calculate the checksum value. Derive the font character from the checksum value and append to the data. At last enclose the whole part with either asterisks or square brackets.

Table 4.1. Code39 value table

charvaluecharvaluecharvaluecharvalue
00A10N23hyphen (-)36
11B11O24period (.)37
22C12P25SPACE ( )38
33D13Q26dollar ($)39
44E14R27slash (/)40
55F15S28plus (+)41
66G16T29percent (%)42
77H17U30  
88I18V31  
99J19W32  
  K20X33  
  L21Y34  
  M22Z35  

The following procedure explains how to calculate the modulo 43 checksum:

  1. First assign each character in the barcode a numeric value (0 through 42) according to Table 4.1, “Code39 value table”. The start and stop characters do not participate in the checksum calculation.

  2. Sum the values of all the data characters.

  3. Divide the result from step 2 by 43.

  4. The remainder from the division in step 3 is the checksum character that will be appended to the data message before the stop character.

Note that in Code39 font the SPACE character is represented by equal = sign or underscore _. This also applies on checksum values. If you get a checksum value of 38, you should add = to the barcode string instead.

4.4. Code 39 Extended

Code39 standard also specifies a way to print characters outside the native Code 39 character set. It does so by encoding these characters with two native Code 39 characters. Four characters, the percent sign (%), dollar ($), slash (/) and plus sign (+) are used as leading characters.

Since these leading characters are also in the native Code 39 character set, the barcode reader is unable to determine whether a barcode is Code 39 extended or just normal code 39. For example, a barcode reader may read the extended code 39 barcode abc as +A+B+C. Fortunately, most scanners allow you configure if you expect a Code 39 extended symbol (sometimes called Code 39 Full ASCII), or just a normal code 39 symbol.

When you need to encode characters outside the native set, use the table below. For example, the sequence for lower case letter a is +A.

Table 4.2. Code39 Full ASCII Chart

ASCIIEncodingASCIIEncodingASCIIEncodingASCIIEncoding
NUL%USpace= or -@%V`%W
SOH$A!/AAAa+A
STX$B"/BBBb+B
ETX$C#/CCCc+C
EOT$D$/DDDd+D
ENQ$E%/EEEe+E
ACK$F&/FFFf+F
BEL$G'/GGGg+G
BS$H(/HHHHH
HT$I)/IIIi+I
LF$J*/JJJj+J
VT$K+/KKKk+K
FF$L,/LLLl+L
CR$M--MMm+M
SO$N..NNn+N
SI$O//OOOo+O
DLE$P00PPp+P
DC1$Q11QQq+Q
DC2$R22RRr+R
DC3$S33SSs+S
DC4$T44TTt+T
NAK$U55UUu+U
SYN$V66VVv+V
ETB$W77WWw+W
CAN$X88XXx+X
EM$Y99YYy+Y
SUB$Z:/ZZZz+Z
ESC%A;%F[%K{%P
FS%B>%G\%L|%Q
GS%C=%H]%M}%R
RS%D<%I^%N~%S
YS%E?%J_%ODEL%T, %X, %Y, %Z

To create barcode string for extended code39, first convert character outside the code39 set to two characters. Add start/stop character at the beginning and the end. Formatting the result with a code39 font will result in an extended code 39 barcode.



[4] Uniform Symbology Specification

Do you know?

This manual is specific to Code39 PCL Scalable Fonts 1.0.
The current version is 1.0.0.

This Manual is also available in the following format: PDF.