String array to Hex Array (Java) -


I have a string array that actually consists of hex characters.

We say that the content is - & gt;

  string array [] = {8C, D9, 26,1D, 69, B796, DB};   

Now I want to define them as hex characters of 1 byte and not in the form of string, where each entry is 2 bytes.

  stringbuilder output = new stringbiller (); For (int j = 0; j & lt; array.length; j ++) {string tag = "\ u00" + array [j]; Output.append (temporary); }   

Tried to do something like that, but this is not possible because it complains about "illegal Unicode escape" to get around that error, "\ u00" Instead of "\ u00" (i.e. the first two backslashes in the UK, but the stack overflow shows only one), but then I do not see the real hex value in the array, instead see a bunch of strings like I do - & gt; "\ U008C", "\ U00D9" and so on ..

I want 0x8C, 0xD9, 0x26 ... after conversion values, thanks.

Edit: I have updated this question, just to make it clear that there was no comma in any swap. And finally I should put all those values ​​together, and use it as a HMCAC key which is a hex string and not a text string.

  string [] array = {"8c", " D9 "," 26 "," 1d "," 69 "," B7 "," 96 "," db "}; Stringbinder output = new stringbiller (); For (string hex: array) {output.append (four) integer. Parasont (hex, 16)); }   

Actually you just need a line inside the loop.

If you want your input just a big string (which will look more comfortable), instead:

  string input = "8CD9261D69B796DB"; Stringbinder output = new stringbiller (); (String hex: input.reset all (".. (?! $)", "$ 0,"). Split (",")} {output.append (four) integer. PRIINT (hex, 16 )); }   

Edit:

If you want a byte [] result, do this:

  string [] array = { "8C", "D9", "26", "1d", "69", "B7", "96", "DB"}; Byte [] bytes = new byte [array.length]; For (int i = 0; i & lt; arrays.label; i ++) {bytes [ii] = (byte) integer.pressant (array [i], 16); }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -