I am having a hard time trying to convert a String containing the hex string representation to its corresponding hex string byte array.
I tried this code
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) (((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s
.charAt(i + 1), 16)) & 0xFF);
}
return data;
}
It's not the exact value what i am looking for above code conveting "FF" --> -1.
Expecting is "FF" --> byte[] { FF }.
Ex : "01FF0A2357F01A" result should be like this byte[] { 01 FF 0A 12 57 F0 1A }.