If you want to parse unsigned hexadecimal strings, use
byte[] b = new byte[a.length()];
for (int i=0; i<a.length(); i++) {
b[i] = (byte) Short.parseShort(a[i], 16);
}
"ff" will be parsed to -1, according to two compliments .
If you want ff to parse up to 255 (higher than Java bytes can be stored), you will need to use shorts
short[] b = new short[a.length()];
for (int i=0; i<a.length(); i++) {
b[i] = Short.parseShort(a[i], 16);
}
source
share