I have a String array that actually consists of Hex characters.
Let's say the contents are ->
String array[] = {8C,D9,26,1D,69,B7,96,DB};
Now I want these to be interpreted as Hex characters of 1 byte each and not as a String where each entry is 2 bytes.
StringBuilder output = new StringBuilder();
for (int j = 0; j < array.length; j++) {
String temp = "\u00"+ array[j];
output.append(temp);
}
Tried something like that, but it's not possible because it keeps complaining about "illegal unicode escape". I tried using "\u00" (i.e. two backslashes before u, but stackoverflow displays only one there) instead of "\u00" to get around that error, but then I don't see the real Hex values in the array, instead I see a bunch of strings like -> "\U008C" , "\U00D9" and so on..
I want the after conversion values to be 0x8C, 0xD9, 0x26...
Thanks.
EDIT: I have updated the question, just to clarify there were no commas in the array itself. And eventually I need to put all those values together, and use that as a HMAC key that is a hex string and NOT a text string.
byte[]
as your output? Your example above is misleading if so since you are building a String. – cklab Jul 12 '12 at 2:16"\u00" + array[j]
wouldn't do you any good, anyway. The first part of Bohemian's answer is what you need, I think. – David Conrad Jul 12 '12 at 3:00