Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hex string with zeros left padded

To left pad a number with zeros if there are fewer than two digits we use this:

String.format("%02d", aBlkNo);

However, aBlkNo should be a hex string not a decimal. What can I do to render a two digit hex string from a byte with zeros padded when necessary?

like image 522
Blair Osbay Avatar asked Oct 20 '25 06:10

Blair Osbay


1 Answers

Use "x" or "X" instead of "d":

String.format("%02x", aBlkNo);
like image 82
Sci Prog Avatar answered Oct 22 '25 20:10

Sci Prog