简体   繁体   English

如何在c中将ascii和扩展ascii转换为int

[英]how to convert ascii and extended ascii to int in c

Is there a way to have the decimal value (in int) of ASCII / extended ASCII characters in C (especially the extended ones) 有没有办法在C中拥有ASCII /扩展ASCII字符的十进制值(以int为单位)(特别是扩展的)

ASCII & extended ASCII table : http://www.theasciicode.com.ar/ ASCII和扩展ASCII表: http : //www.theasciicode.com.ar/

Example of my problem with some code : 我的一些代码问题的示例:

int a = (int) 'a';
int b = (int) '│';

printf("%i\n", a);
printf("%i\n", b);

and the output is : 输出为:

97
14849154

in the ASCII table, "│" is normally 179. 在ASCII表中,“│”通常为179。

OP' platform is using implementation defined behavior concerning string literals outside the basic coding set. OP'平台正在使用有关基本编码集之外的字符串文字的实现定义的行为。

UTF-8 encoding. UTF-8编码。 The '│' is a Unicode character U+2502 '│'是Unicode字符U + 2502

When coded as a UTF-8, it has the 3-byte sequence 0xE2 0x94 0x82 or in big endian order: 0xE29482 which is 14849154 (decimal) as printed out by OP. 当编码为UTF-8时,它具有3字节的序列0xE2 0x94 0x82或大字节序:0xE29482,即14849154(十进制),由OP打印。

 int b = (int) '│';

Note: ASCII is only defined for codes 0 to 127. 注意: ASCII仅针对代码0到127定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM