问题
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.
回答1:
Create original_value
using the String(byte[] bytes, String charsetName) constructor:
String original_value = new String(Hex.decodeHex(hexString.toCharArray()), "cp424");
来源:https://stackoverflow.com/questions/10293502/convert-string-to-hex-and-back-with-different-encoding