Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c - Encode extended ASCII characters in a Code 128 barcode

I want to encode the string "Qui?ones" in a Code 128 bar code. Is it possible to include extended ASCII characters in the Code 128 encoding? .

I did some research on Google which suggested that it is possible by using FNC4, but I didn't find exactly how to do it. It would be of great help if some one could assist me with a solution in the C language.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"Extended ASCII" characters with byte values from 128 to 255 can indeed be represented in Code 128 encodation by using the special FNC4 function character. For general use (in open applications) it is necessary that such characters belong to the ISO-8859-1 (Latin1) character set.

A single FNC4 character acts as a shift to the extended character set for the next character whereas two consecutive FNC4 characters act as a latch. The effect is to toggle the high bit (basically to add or subtract 128) of the 8-bit ASCII value of the affected characters.

In your example "Qui?ones" the character "?" is represented by byte value 209 in the default ISO-8859-1 character set, so that's 128+81. ASCII 81 resolves to "Q", so you require the sequence FNC4 Q to represent "?".

An efficient Code 128 encodation of this data is as follows:

[104/START-B] [49/Q] [85/u] [73/i] [100/FNC4] [49/Q] [79/o] [78/n] [69/e] [83/s] [93/check-digit] [106/STOP]

Some barcode applications and libraries will perform the FNC4-based extended character encoding for you, as in the example below. The majority don't but these should allow you to specify an FNC4 character directly so that you can manually drive the process using the above technique, e.g: Qui{FNC4}Qones

The Code 128 symbol looks like this:

Code 128 containing the word "Qui?ones"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...