I would like to convert a byte to its hex from string, when I use method
Integer.toHexString
, the positive number is OK, but the negative number is outputed as
something like ffffffa7
, I would like to always get two char string, how to do that?
Why there is no toHexString
method in the Byte class?
You can use String.format:
String.format("%02x", value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With