I would like to be able to convert a raw UTF-8 string to a Hex string.
In the example below I’ve created a sample UTF-8 string containing 2 letters.
Then I’m trying to get the Hex values but it gives me negative values.
How can I make it give me 05D0 and 05D1
String a = "\u05D0\u05D1";
byte[] xxx = a.getBytes("UTF-8");
for (byte x : xxx) {
System.out.println(Integer.toHexString(x));
}
Thank you.
Don’t convert to an encoding like UTF-8 if you want the code point. Use Character.codePointAt.
For example: