|
Ha ha, I do n’t think it is right
Rewritten
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);
}
test
String a = "测";
System.out.println (getGBK (a));
System.out.println (getGBKINT (a)); |
|