Integer to two digits hex in Java

By | August 3, 2019

Question

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.

Solution

String.format("%02X", value);

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

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *