Thanks for your answer... I have 31 32 2E 30 31 33 6byte hexadecimal number. I want to convert 31 32 2E 30 31 33 this 6 byte hexadecimal number into 12.013 ASCII number in java.
3 Answers
Assuming that your input is an array of strings representing the digits in hex, you can do the following:
public static String convert(String[] hexDigits){
byte[] bytes = new byte[hexDigits.length];
for(int i=0;i<bytes.length;i++)
bytes[i] = Integer.decode("0x"+hexDigits[i]).byteValue();
String result;
try {
result = new String(bytes, "ASCII");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return result;
}
Note that the code assumes that the digits are given as valid ASCII values, with no radix specifier.