This a code for converting hex to string but it works fine until size of the string doesn’t exceeds 62 characters?
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: String index out of range:
62
at java.lang.String.substring(Unknown Source)
at HEX.hexToString(HEX.java:36)
at HEX.main(HEX.java:56)
You will face this problem only when you have odd number of characters in your string. Fix your function as follows: