Regarding the HexString method in Integer?

I would like to convert a byte to its hexadecimal from a string, when I use the method Integer.toHexString, a positive number is ok, but a negative number is output as something like ffffffa7, I would like to get two char strings, how to do it?

Why is there no method in the Byte class toHexString?

+5
source share
1 answer

You can use String.format :

String.format("%02x", value)
+5
source

All Articles