还是编码 汉字(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对照表的打印方法:

// 打印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码:

//  知道一个汉字,获取其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码,输出汉字:

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

  

上一篇:python中xrange()和range()函数的区别使用:


下一篇:ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030等几种常用编码区别(转载)