android - Hex to Ascii conversion -
I hex Bluetooth socket to read ( example: 0x61 0x62 0x63
).
I want to get it related ASCII ( example: ABC
).
How to make this conversion?
I tried:
string s = "0x56 0x49 0x4e 0x31 0x32 0x33 0x46 0x4f 0x52 0x44 0x54 0x52 0x55 0x43 0x4 B 0x00 0x38 "; Stringbilder sb = new string builder (s.length () / 2); For (int i = 0; i & lt; s.length (); i + = 2) {string hex = "" + s.charAt (i) + s.charAt (i + 1); Int is = integer. Persicent (hex, 16); Sb.append ((four) ival); } String string = sb.toString ();
It should work:
string S = "0x56 0x49 0x4e 0x31 0x32 0x33 0x46 0x4f 0x52 0x44 0x54 0x52 0x55 0x43 0x4 B 0x00 0x38"; Stringbilder sb = new stringbiller (); String [] components = s.split (""); (String component: components) for {int ival = integer.print (component location ("0x", "", 16); Sb.append ((four) ival); } String string = sb.toString ();