I am stuck with these problem that how to convert a hex string to unsigned byte array or an Integer array..
Please look in this example.
String s= "1f5621ff8963545a12152250"; //this is my hex string
i want to convert this string to an int array
int buff[]={0x1f,0x56,0x21,0xff,0x89,0x63,0x54,0x5a,0x12,0x15,0x22,0x50};
how could i do that...
thanks for help..
One easy way: compute the length of your int array by dividing the length of the String by 2. Loop over the string, calling substring() to create the two-character strings "1f", "56", etc. Pass each string to Integer.parseInt(string, 16) (the second argument means that the argument is a hex string.) Store the results in the array as you compute them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With