user567 user567 - 1 month ago 11
Java Question

Convert from big Endian to Hex String with java

How can I convert from 16-bit unsigned integer big Endian to Hex String? I want to make the inverse of what you can see in the screenshot.
enter image description here

From the Big Endian value

13089
I want to have as a result
3321
. I tried this but I got as result
71 48 97 92
which is a totally different value that expected

Integer.reverseBytes(value);

Answer

You can use this:

String hex = Integer.toHexString(13089);
System.out.println(hex) //prints 3321

You don't have to reverse bytes because its already a big-endian representation.