java字符串16进制怎么转换成数值

如题所述

使用这个方法可以传进去的16进制的数字组成的字符串转化为utf-8格式的字符串

public static String toStringHex1(String s) {
byte[] baKeyword = new byte[s.length() / 2];
for (int i = 0; i < baKeyword.length; i++) {
try {
baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(
i * 2, i * 2 + 2), 16));
} catch (Exception e) {
e.printStackTrace();
}
}
try {
s = new String(baKeyword, "utf-8");// UTF-16le:Not
} catch (Exception e1) {
e1.printStackTrace();
}
return s;
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2017-04-21
Integer.parseInt("ffffff",16);
相似回答