条码规范——Code 128



CODE 128 BACKGROUND INFORMATION
Code 128 is a very effective, high-density symbology which permits the encoding of alphanumeric data. The symbology includes a checksum digit for verification, and the bar code may also be verified character-by-character verifying the parity of each data byte. This symbology has been widely implemented in many applications where a relatively large amount of data must be encoded in a relatively small amount of space. It's specific structure also allows numeric data to be encoded at, effectively, double-density.

An example of alphanumeric encoding in a single Code 128 bar code is:

COMPUTING THE CHECKSUM DIGIT
Before a Code 128 symbol may be encoded, the software must compute the correct checksum digit which will be included in the bar code. The checksum digit is based on a modulo 103 calculation based on the weighted sum of the values of each of the digits in the message that is being encoded, including the start character.

The steps for calculating the check digit are as follows:

  1. Take the value of the start character (103, 104, or 105) and make that the starting value of the running checksum.
  2. Starting with the first data character following the start character, take the value of the character (between 0 and 102, inclusive) multiply it by its character position (1) and add that to the running checksum.
  3. Take each additional character in the message, take its value, and multiply it by its character position, and add the total to the running checksum.
  4. Divide the resulting running checksum by 103. The remainder becomes the checksum digit which is added to the end of the message.
  5. The stop character is appended after the checksum digit.
This is easier to understand with an example. Let's calculate the checksum digit for the sample bar code above, " HI345678". The checksum digit is included in all Code 128 bar codes, but it isn't printed as part of the text below the bar code symbol (as is the case with UPC and EAN symbols).
BarcodeSTART-AHICODE-C345678
Character Value103404199345678
Character Position-123456
Calculation10340 * 141 * 299 * 334 * 456 * 578 * 6
Weighted Sum1034082297136280468

Summing up the running checksum for each digit, we get 103 + 40 + 82 + 297 + 136 + 280 + 468 = 1406. This value divided by 103 is 1406 / 103 = 13 with a remainder of 67. Thus the checksum digit is the character which has a value of 67.

  • NOTE: Note that the checksum starts with the first Start Character, with a weight of 1, and that the first data character also has a weight of 1.
ENCODING THE SYMBOL
Once the checksum digit has been calculated we know the entire message which must be encoded in the bars and spaces. Continuing with our example, we will encode, from zero, the Code 128 bar code we used in our example above:  HI345678with a checksum digit of 67.

In the following text, we will discuss the encoding of the bar code by considering that the number "1" represents a "dark" or "bar" section of the bar code whereas a "0" represents a "light" or "space" section of the bar code. Thus the numbers 1101 represents a double-wide bar (11), followed by a single-wide space (0), followed by a single-wide bar (1). This would be printed in the bar code as:


STRUCTURE OF A CODE 128 BARCODE
A Code 128 bar code consists of a leading quiet zone, one of three start codes, the data itself, a check character, a stop character, and a trailing quiet zone.

The Code 128 specification defines three "character sets" or "character modes." The start code that is used determines which character set will be used. The character set may also be changed in the middle of the bar code. For example, in the bar code above the bar code starts in "Character set A" to encode the text "HI", and then switches to "Character set C" to more efficiently encode the numbers that follow.

To encode a value as a Code 128 bar code, the checksum digit must first be calculated (see procedure above) and the entire bar code, including check digit, may then be encoded as a sequence of bars and spaces.

A Code 128 bar code has the following physical structure:

  1. Start code, which is the code 103, 104, or 105 from the encoding table below (either 11010000100 (Start-A), 11010010000 (Start-B), or 11010011100 (Start-C).
  2. Each of the data bytes of the message, encoded with the encoding table below.
  3. The checksum byte, calculated as described above and encoded using the table below.
  4. Stop character of 11000111010.
  5. Termination bar of 11.
CODE 128 ENCODING TABLE
This table indicates how to encode each digit of a Code 128 bar code. Note that it is easiest to think of each character as a value between 0 and 105, inclusive, rather than thinking of them as characters. The character that a value represents depends on what mode (or character set) you're in-so rather than thinking of a character as "A" or "B", etc. it is more appropriate to think of it as 33, 34, etc.

VALUEWHICH REPRESENTS IN
CHARACTER SET
ENCODINGVALUEWHICH REPRESENTS IN
CHARACTER SET
ENCODING
ABCABC
00SPSP001101100110053UU5311011101110
01!!011100110110054VV5411101011000
02""021100110011055WW5511101000110
03##031001001100056XX5611100010110
04$$041001000110057YY5711101101000
05%%051000100110058ZZ5811101100010
06&&061001100100059[[5911100011010
07''071001100010060\\6011101111010
08((081000110010061]]6111001000010
09))091100100100062^^6211110001010
10**101100100010063__6310100110000
11++111100010010064NUL`6410100001100
12,,121011001110065SOHa6510010110000
13--131001101110066STXb6610010000110
14..141001100111067ETXc6710000101100
15//151011100110068EOTd6810000100110
1600161001110110069ENQe6910110010000
1711171001110011070ACKf7010110000100
1822181100111001071BELg7110011010000
1933191100101110072BSh7210011000010
2044201100100111073HTi7310000110100
2155211101110010074LFj7410000110010
2266221100111010075VTk7511000010010
2377231110110111076FFl7611001010000
2488241110100110077CRm7711110111010
2599251110010110078SOn7811000010100
26::261110010011079SIo7910001111010
27;;271110110010080DLEp8010100111100
28<<281110011010081DC1q8110010111100
29==291110011001082DC2r8210010011110
30>>301101101100083DC3s8310111100100
31??311101100011084DC4t8410011110100
32@@321100011011085NAKu8510011110010
33AA331010001100086SYNv8611110100100
34BB341000101100087ETBw8711110010100
35CC351000100011088CANx8811110010010
36DD361011000100089EMy8911011011110
37EE371000110100090SUBz9011011110110
38FF381000110001091ESC{9111110110110
39GG391101000100092FS|9210101111000
40HH401100010100093GS}9310100011110
41II411100010001094RS~9410001011110
42JJ421011011100095USDEL9510111101000
43KK431011000111096FNC3FNC39610111100010
44LL441000110111097FNC2FNC29711110101000
45MM451011101100098SHIFTSHIFT9811110100010
46NN461011100011099Code CCode C9910111011110
47OO4710001110110100Code BFNC4Code B10111101110
48PP4811101110110101FNC4Code ACode A11101011110
49QQ4911010001110102FNC1FNC1FNC111110101110
50RR5011000101110103START ASTART ASTART A11010000100
51SS5111011101000104START BSTART BSTART B11010010000
52TT5211011100010105START CSTART CSTART C11010011100
  STOPSTOPSTOP11000111010
CODE 128 ENCODING EXAMPLE
We will now code the above example,  HI345678, in Code 128. As we calculated in the Checksum Digit Calculation section, the checksum digit is  67. So we must also code the checksum digit at the end of the message.

We encode each digit using the encoding table above.

  1. The START-A character: 11010000100.
  2. The digit "H" encoded as: 11000101000.
  3. The digit "I" encoded as: 11000100010.
  4. The "CODE-C" character: 10111011110.
  5. The digits "34" encoded as: 10001011000.
  6. The digits "56" encoded as: 11100010110.
  7. The digits "78" encoded as: 11000010100.
  8. The checksum digit of 67 encoded as: 10000101100.
  9. The STOP character: 11000111010.
  10. The termination bar: 11.
This is shown in the following graphical representation where the bar code has been sectioned-off into areas that reflect each of the 10 components just mentioned.

CODE 128 BACKGROUND INFORMATION
Code 128 is a very effective, high-density symbology which permits the encoding of alphanumeric data. The symbology includes a checksum digit for verification, and the bar code may also be verified character-by-character verifying the parity of each data byte. This symbology has been widely implemented in many applications where a relatively large amount of data must be encoded in a relatively small amount of space. It's specific structure also allows numeric data to be encoded at, effectively, double-density.

An example of alphanumeric encoding in a single Code 128 bar code is:

COMPUTING THE CHECKSUM DIGIT
Before a Code 128 symbol may be encoded, the software must compute the correct checksum digit which will be included in the bar code. The checksum digit is based on a modulo 103 calculation based on the weighted sum of the values of each of the digits in the message that is being encoded, including the start character.

The steps for calculating the check digit are as follows:

  1. Take the value of the start character (103, 104, or 105) and make that the starting value of the running checksum.
  2. Starting with the first data character following the start character, take the value of the character (between 0 and 102, inclusive) multiply it by its character position (1) and add that to the running checksum.
  3. Take each additional character in the message, take its value, and multiply it by its character position, and add the total to the running checksum.
  4. Divide the resulting running checksum by 103. The remainder becomes the checksum digit which is added to the end of the message.
  5. The stop character is appended after the checksum digit.
This is easier to understand with an example. Let's calculate the checksum digit for the sample bar code above, " HI345678". The checksum digit is included in all Code 128 bar codes, but it isn't printed as part of the text below the bar code symbol (as is the case with UPC and EAN symbols).
BarcodeSTART-AHICODE-C345678
Character Value103404199345678
Character Position-123456
Calculation10340 * 141 * 299 * 334 * 456 * 578 * 6
Weighted Sum1034082297136280468

Summing up the running checksum for each digit, we get 103 + 40 + 82 + 297 + 136 + 280 + 468 = 1406. This value divided by 103 is 1406 / 103 = 13 with a remainder of 67. Thus the checksum digit is the character which has a value of 67.

  • NOTE: Note that the checksum starts with the first Start Character, with a weight of 1, and that the first data character also has a weight of 1.
ENCODING THE SYMBOL
Once the checksum digit has been calculated we know the entire message which must be encoded in the bars and spaces. Continuing with our example, we will encode, from zero, the Code 128 bar code we used in our example above:  HI345678with a checksum digit of 67.

In the following text, we will discuss the encoding of the bar code by considering that the number "1" represents a "dark" or "bar" section of the bar code whereas a "0" represents a "light" or "space" section of the bar code. Thus the numbers 1101 represents a double-wide bar (11), followed by a single-wide space (0), followed by a single-wide bar (1). This would be printed in the bar code as:


STRUCTURE OF A CODE 128 BARCODE
A Code 128 bar code consists of a leading quiet zone, one of three start codes, the data itself, a check character, a stop character, and a trailing quiet zone.

The Code 128 specification defines three "character sets" or "character modes." The start code that is used determines which character set will be used. The character set may also be changed in the middle of the bar code. For example, in the bar code above the bar code starts in "Character set A" to encode the text "HI", and then switches to "Character set C" to more efficiently encode the numbers that follow.

To encode a value as a Code 128 bar code, the checksum digit must first be calculated (see procedure above) and the entire bar code, including check digit, may then be encoded as a sequence of bars and spaces.

A Code 128 bar code has the following physical structure:

  1. Start code, which is the code 103, 104, or 105 from the encoding table below (either 11010000100 (Start-A), 11010010000 (Start-B), or 11010011100 (Start-C).
  2. Each of the data bytes of the message, encoded with the encoding table below.
  3. The checksum byte, calculated as described above and encoded using the table below.
  4. Stop character of 11000111010.
  5. Termination bar of 11.
CODE 128 ENCODING TABLE
This table indicates how to encode each digit of a Code 128 bar code. Note that it is easiest to think of each character as a value between 0 and 105, inclusive, rather than thinking of them as characters. The character that a value represents depends on what mode (or character set) you're in-so rather than thinking of a character as "A" or "B", etc. it is more appropriate to think of it as 33, 34, etc.

VALUEWHICH REPRESENTS IN
CHARACTER SET
ENCODINGVALUEWHICH REPRESENTS IN
CHARACTER SET
ENCODING
ABCABC
00SPSP001101100110053UU5311011101110
01!!011100110110054VV5411101011000
02""021100110011055WW5511101000110
03##031001001100056XX5611100010110
04$$041001000110057YY5711101101000
05%%051000100110058ZZ5811101100010
06&&061001100100059[[5911100011010
07''071001100010060\\6011101111010
08((081000110010061]]6111001000010
09))091100100100062^^6211110001010
10**101100100010063__6310100110000
11++111100010010064NUL`6410100001100
12,,121011001110065SOHa6510010110000
13--131001101110066STXb6610010000110
14..141001100111067ETXc6710000101100
15//151011100110068EOTd6810000100110
1600161001110110069ENQe6910110010000
1711171001110011070ACKf7010110000100
1822181100111001071BELg7110011010000
1933191100101110072BSh7210011000010
2044201100100111073HTi7310000110100
2155211101110010074LFj7410000110010
2266221100111010075VTk7511000010010
2377231110110111076FFl7611001010000
2488241110100110077CRm7711110111010
2599251110010110078SOn7811000010100
26::261110010011079SIo7910001111010
27;;271110110010080DLEp8010100111100
28<<281110011010081DC1q8110010111100
29==291110011001082DC2r8210010011110
30>>301101101100083DC3s8310111100100
31??311101100011084DC4t8410011110100
32@@321100011011085NAKu8510011110010
33AA331010001100086SYNv8611110100100
34BB341000101100087ETBw8711110010100
35CC351000100011088CANx8811110010010
36DD361011000100089EMy8911011011110
37EE371000110100090SUBz9011011110110
38FF381000110001091ESC{9111110110110
39GG391101000100092FS|9210101111000
40HH401100010100093GS}9310100011110
41II411100010001094RS~9410001011110
42JJ421011011100095USDEL9510111101000
43KK431011000111096FNC3FNC39610111100010
44LL441000110111097FNC2FNC29711110101000
45MM451011101100098SHIFTSHIFT9811110100010
46NN461011100011099Code CCode C9910111011110
47OO4710001110110100Code BFNC4Code B10111101110
48PP4811101110110101FNC4Code ACode A11101011110
49QQ4911010001110102FNC1FNC1FNC111110101110
50RR5011000101110103START ASTART ASTART A11010000100
51SS5111011101000104START BSTART BSTART B11010010000
52TT5211011100010105START CSTART CSTART C11010011100
  STOPSTOPSTOP11000111010
CODE 128 ENCODING EXAMPLE
We will now code the above example,  HI345678, in Code 128. As we calculated in the Checksum Digit Calculation section, the checksum digit is  67. So we must also code the checksum digit at the end of the message.

We encode each digit using the encoding table above.

  1. The START-A character: 11010000100.
  2. The digit "H" encoded as: 11000101000.
  3. The digit "I" encoded as: 11000100010.
  4. The "CODE-C" character: 10111011110.
  5. The digits "34" encoded as: 10001011000.
  6. The digits "56" encoded as: 11100010110.
  7. The digits "78" encoded as: 11000010100.
  8. The checksum digit of 67 encoded as: 10000101100.
  9. The STOP character: 11000111010.
  10. The termination bar: 11.
This is shown in the following graphical representation where the bar code has been sectioned-off into areas that reflect each of the 10 components just mentioned.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值