2

I am trying to decode some hex values to their actual names, but i am having issue.

21043D0438043C043E043A04 should be decoded to СНИМОК. Current code I am using

String test = "21043D0438043C043E043A04";
byte[] bytes = Hex.decodeHex(test.toCharArray());               
String a = new String(bytes, "UTF-8");

but i am getting some pretty weird results.

Tried also getting it as utf8 bytes but did not work.

byte[] bytesone = test.getBytes(Charset.forName("UTF-8"));
String b = new String(bytesone, Charset.forName("UTF-8"));
byte[] bytes = Hex.decodeHex(b.toCharArray());              
String a = new String(bytes, "UTF-8");

Thanks in advance

6
  • Can you show the code used to encode the text? Commented Dec 11, 2017 at 13:30
  • sadly i am having these values in a file Commented Dec 11, 2017 at 13:31
  • What class is Hex? Commented Dec 11, 2017 at 13:31
  • org.apache.commons.codec.binary.Hex Commented Dec 11, 2017 at 13:33
  • The string "21043D0438043C043E043A04" is not a utf-8 hex encoding of "СНИМОК". "d0a1d09dd098d09cd09ed09a" is. Commented Dec 11, 2017 at 13:33

2 Answers 2

4

\u0421 is the Cyrillic С so the code seems UTF-16LE (little endian).

String a = new String(bytes, "UTF-16LE");
String a = new String(bytes, StandardCharsets.UTF_16LE);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for you quick answer ! Strangely enough I am now getting ?????? in the console.
The console is probably OS dependent with its encoding, that cannot handle Cyrillic script. Unrepresentable Unicode code points, will be converted to a place holder.
3

This looks more like UTF-16LE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.