/**
* 16进制转化为字母
* @param hex 要转化的16进制数,用逗号隔开
* 如:53,68,61,64,6f,77
* @return
*/
public static String hex2Str(String hex) {
StringBuilder sb = new StringBuilder();
String[] split = hex.split(",");
for (String str : split) {
int i = Integer.parseInt(str, 16);
sb.append((char)i);
}
return sb.toString();
}
/**
* 字符串中每个字母转化为16进制
* @param letter
* @return
*/
public static String str2Hex(String letter) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < letter.length(); i++) {
char c = letter.charAt(i);
sb.append(Integer.toHexString(c));
sb.append(", ");
}
sb.deleteCharAt(sb.length() - 2);
return sb.toString();
}