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
intarray by dividing the length of theStringby 2. Loop over the string, callingsubstring()to create the two-character strings “1f”, “56”, etc. Pass each string toInteger.parseInt(string, 16)(the second argument means that the argument is a hex string.) Store the results in the array as you compute them.