例如现在有个 "测 "字 它的UNICODE的ASCII码为27979 16进制ASCII码为6D4B
现在要转化为GBK内码,也就是要得到 "测 "字的GBK的ASCII码:45794,然后我把他转换成16进制。。。问大家的就是如何得到汉字的GBK内码的ASCII码?
谢谢了
------解决方案--------------------
呵呵 我也觉得不对 超过字符集范围了 没闷过去
重写了个
public static String getGBK(String a) throws UnsupportedEncodingException{
byte[] b=new String(a).getBytes( "gbk ");
String b1=Integer.toString((char)b[0],16).toUpperCase();
String b2=Integer.toString((char)b[1],16).toUpperCase();
return b1.substring(2,4)+b2.substring(2, 4);
}
public static int getGBKINT(String a) throws UnsupportedEncodingException{
String tmp=getGBK(a);
return Integer.parseInt(tmp, 16);
}
测试
String a= "测 ";
System.out.println(getGBK(a));
System.out.println(getGBKINT(a));
------解决方案--------------------
终于知道我第一种写法那里错了,位数和高地位搞错了
char aa = '测 ';
byte[] b = new String( "测 ").getBytes( "gbk ");
int high = b[0] < < 8 & 0xFFFFFF00;
int low = b[1]&0xFFFF00FF;
int gbk = (high | low) & 0x0000FFFF;
System.out.println(Integer.toHexString((gbk)));
System.out.println(gbk);
------解决方案--------------------
char aa = '测 ';
byte[] b = new String( "测 ").getBytes( "gbk ");
int high = b[0] < < 8 & 0xFFFFFF00;
int low = b[1]&0xFFFF00FF;
int gbk = (high | low) & 0x0000FFFF;
System.out.println(Integer.toHexString((gbk)));
System.out.println(gbk);