这是将十六进制转换为字符串的代码,但在字符串大小不超过 62 个字符之前它可以正常工作?
public static String hexToString(String hex)
{
StringBuilder output = new StringBuilder();
for (int i = 0; i < hex.length(); i+=2)
{
String str = hex.substring(i, i+2);
output.append((char)Integer.parseInt(str, 16));
}
return(output.toString());
}
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:HEX.hexToString(HEX.java:36) 处 HEX.main(HEX.java:56) 处的 java.lang.String.substring(Unknown Source) 处为 62