user590586
user590586

Reputation: 3050

convert string to hex and back with different encoding

I want to convert a String value to hex and then back to it's ascii value. when I'm converting it to the hex value i'm doing it with the charset - cp424.

this is what i'm trying to do:

String str = "abcאבג";               
String hexString = Hex.encodeHexString(str.getBytes("cp424")); 
//some action         
String original_value = Hex.decodeHex(hexString.toCharArray()).toString();

My problem is beacuse i'm using cp424 when converting to hex I need when converting back to get it back to the defult charset. I tried this convertion in many ways but didn't get the correct value.

how can this be done? how can i get back the original value from the hex value??

Thank's In Advance.

Upvotes: 0

Views: 2879

Answers (1)

eggyal
eggyal

Reputation: 125835

Create original_value using the String(byte[] bytes, String charsetName) constructor:

String original_value = new String(Hex.decodeHex(hexString.toCharArray()), "cp424");

Upvotes: 2

Related Questions