Integer to two digits hex in Java

Salih Erikci picture Salih Erikci · Dec 31, 2011 · Viewed 88.1k times · Source

I need to change a integer value into 2-digit hex value in Java.Is there any way for this. Thanks

My biggest number will be 63 and smallest will be 0. I want a leading zero for small values.

Answer

GabrielOshiro picture GabrielOshiro · Oct 10, 2013
String.format("%02X", value);

If you use X instead of x as suggested by aristar, then you don't need to use .toUpperCase().