简体   繁体   中英

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)

ASCII & extended ASCII table : 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.

OP' platform is using implementation defined behavior concerning string literals outside the basic coding set.

UTF-8 encoding. The '│' is a Unicode character 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.

 int b = (int) '│';

Note: ASCII is only defined for codes 0 to 127.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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