Java Convert integer to hex integer

user1215143 picture user1215143 · Feb 17, 2012 · Viewed 168.1k times · Source

I'm trying to convert a number from an integer into an another integer which, if printed in hex, would look the same as the original integer.

For example:

Convert 20 to 32 (which is 0x20)

Convert 54 to 84 (which is 0x54)

Answer

Ajith picture Ajith · Nov 3, 2012

The easiest way is to use Integer.toHexString(int)