I'm trying to figure out why String.format()
is behaving the way it does.
Context: Systems programming class, writing an assembler.
There is a 5 character hex field in the object file, which I am creating from a value.
Tried using: String.format("%05X", decInt);
This works as intended for positive numbers
(11 -> 0000B
)
However it fails for negative numbers
(-1 -> FFFFFFFF
instead of FFFFF
)
I suppose I could just take a substring of the last 5 characters, but I would still like to figure out why it behaves this way.
width
set by the format method, in this case 5, is the minimum width.