Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding toHexString method in the Integer?

Tags:

java

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?

like image 440
user705414 Avatar asked Jan 07 '12 08:01

user705414


1 Answers

You can use String.format:

String.format("%02x", value)
like image 80
Howard Avatar answered Nov 15 '22 05:11

Howard