1

How can I convert a word's HEX code string to Shift JIS encoding?

For example, I have a string:

"90DD92E882F08F898AFA89BB82B582DC82B782A9"

And I want to get the following output:

設定を初期化しますか

2

2 Answers 2

2
String s = new String(new BigInteger("90DD92E882F08F898AFA89BB82B582DC82B782A9", 16).toByteArray(), "Shift_JIS");

will do it for you for earlier versions

Sign up to request clarification or add additional context in comments.

Comments

1

Assuming you have Java 17+, which added java.util.HexFormat, then you can use parseHex followed by a conversion from the byte array to a string:

byte[] bytes = HexFormat.of().parseHex("90DD92E882F08F898AFA89BB82B582DC82B782A9");
String str = new String(bytes, "Shift_JIS");

If you do not have Java 17+, then the related answer I linked to gives an alternative approach instead of parseHex.

I don't have the correct charset/font to show the result in my console, but here is the str variable in my debugger:

enter image description here

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.