首页 > 代码库 > 还是编码 汉字(GB2312和GBK)的ASCII码对照表

还是编码 汉字(GB2312和GBK)的ASCII码对照表

GB2312和GBK每一个汉字由2个字节组成,这2个字节的ASCII码大小分别是:
gb2312:

high8 = 0xa1-->0xfe (161 - 254)
low8 = 0xa1-->0xfe  (161 - 254)

gbk:

high8 = 0x80-->0xfe (128 - 254)
low8 = 0x40-->0xfe (64 - 254)

 

GB2312和GBK的区别:http://zhidao.baidu.com/question/40269499

 

汉字ASCII对照表的打印方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
// 打印ASCII汉字编码表
for(int i =  129; i < 256; ++i) //  129 = 0x81 
{
    for(int j = 64; j < 256; ++j) // 64 = 0x40
    {
    char pchar[3];
    pchar[0] = i;
    pchar[1] = j;
    pchar[2] = ‘/0‘;
    cout << pchar << " " << i << "," << j << " ";
    }
}

知道一个汉字,输出其ASCII码:

?
1
2
3
4
5
6
7
8
9
10
//  知道一个汉字,获取其ASCII编码
char * pchar = "中";
//需要先把pchar的每个字符转成unsigned char,
// 直接用int i = pchar[0],得到的是负值
unsigned char ci = pchar[0];
int i = ci;
unsigned char cj = pchar[1];
int j = cj;
cout << pchar << " " << i << "," << j << endl;
// 输出214,208

知道汉字的ASCII码,输出汉字:

?
1
2
3
4
5
6
//  知道汉字的ASCII码输出汉字
char pchar[3];
pchar[0] = 214;
pchar[1] = 208;
pchar[2] = ‘/0‘;
cout << pchar << endl;