请教怎么把16进制字符串转换为Ascii码

如题所述

请教怎么把16进制字符串转换为Ascii码
使用这个方法可以传进去的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个回答  2016-12-06
艺住院细栈蓬松澈
相似回答