-5

Can anyone please help me in converting string to hex and hex to string for following string which is in arabic and english.

 String str = "مصطلحات : RAM : Random";
Ram G
  • 36
  • 1
  • 10
  • 2
    Possible duplicate of [How to convert String to Hex and Hex to String?](http://stackoverflow.com/questions/15020812/how-to-convert-string-to-hex-and-hex-to-string) – sinclair Aug 01 '16 at 07:53

1 Answers1

2
byte[] myBytes = "مصطلحات : RAM : Random".getBytes("UTF-8");
String hexString = DatatypeConverter.printHexBinary(myBytes); // to hex String 

byte[] bytes = Hex.decodeHex(hexString.toCharArray());
new String(bytes, "UTF-8"); // decode it back

I used this question and this answer

Community
  • 1
  • 1
Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192