为什么我的ASCII字符从int转换为int失败?

为什么我的ASCII字符从int转换为int失败?

问题描述:

根据此处的图表:

http://www.idautomation.com/barcode-faq/code- 128/

此字符:

Ë

等于值103.

请输入以下代码:

string barcode = textBoxRawCode128.Text.Trim(); 
. . .
int runningTotal = ConvertToASCIIInt(barCode[0]);
. . .

private int ConvertToASCIIInt(char valToConvertToASCII)
{
    const int ASCII_ADJUSTMENT_VAL = 32;
    return valToConvertToASCII - ASCII_ADJUSTMENT_VAL;
}

...当文本框中的值(因此条形码)为ËTryanother string.",从而条形码[0]为Ë"时,返回值171而不是103 ... ???

...when the value in the textbox and thus of barcode is "ËTry another string.", thus where barcode[0] is "Ë", returns a value of 171 instead of 103...???

并根据此图表: http://www.adams1.com/128table.html,对应于103的值是‡,但是当我将barCode设置为‡Try another string."时,返回的值是8193 ... ???越来越好奇...

And according to this chart: http://www.adams1.com/128table.html, the value corresponding to 103 is ‡, but when I set barCode to "‡Try another string.", the returned value is 8193...??? Curiouser and curiouser...

注意:相关/初步文章为是此代码用于计算Code128条形码检查数字是否正确?

Note: A related/preliminary post is Is this code for calculating Code128 barcode check digits correct?

请记住,要找到Code 128符号的正确数字,您必须减去32,因此要获取Code 128符号103的ASCII值,您必须添加32,从而得到135(不是7位ASCII).亚当斯(Adams)说的很对,但是由于它是高ASCII"字符,因此您会陷入混乱的代码页中.因此,取决于PC的语言,并且如果触摸字符串的应用程序使用的是DBCS或Unicode或8位ASCII,则由于国际标准的不同,您可能会发现不同的字符.如果在Windows字符地图应用程序中调出Small Fonts typefont,则可以找到Russ Adams给定的字符.查看"0x87"下的字符(十进制为135).

Keep in mind that to find the correct number for the Code 128 symbol you have to subtract 32, therefore to get the ASCII value of the Code 128 symbol 103, you'll have to add 32, giving you 135 which is not 7-bit ASCII. Adams has it right, but since it's 'high-ASCII' you get into the mess of code pages. So, depending on the language of the PC and if the applications that touch the string are using DBCS or Unicode or 8-bit ASCII, you may find different characters because the international standards differ. The character given by Russ Adams can be found if you bring up the Small Fonts typefont in the Windows Character Map application. Look at the character under "0x87" which is 135 in decimal.

IDAutomation人员正在使用自己的算法,根据您输入的字母得出条形码字符,因此,如果他们说他们需要一个Ë"来获得103,那么这就是他们所需要的. 'Ë'并不等于103,这只是使他们的软件咳嗽103的原因.这一切都是为了解决从数字7位标准到供应商生产钢筋的方法的转变.

The IDAutomation people are using their own algorithm to arrive at a barcode character based on the letters you feed it, so if they say they need a 'Ë' to get a 103, then that's what they need. 'Ë' doesn't equate to a 103, it's just what gets their software to cough up a 103. This is all to work around the conversion from a numeric 7-bit standard to the vendor's method for producing bars.

遗憾的是,不同的符号系统没有使用相同的算法来编码数据或导出校验和,因此每种条形码类型都必须具有自己的软件.

Sadly, different symbologies do not use the same algorithms for encoding data or deriving checksums, so each barcode type has to have its own software.