String.format("%02X", value);
If you use X instead of x as suggested by aristar, then you don’t need to use .toUpperCase().
String.format("%02X", value);
If you use X instead of x as suggested by aristar, then you don’t need to use .toUpperCase().