title: String.format() and hex numbers in Java
body: <p>I'm trying to figure out why <code>String.format()</code> is behaving the way it does.</p>
  
  <p>Context: Systems programming class, writing an assembler.</p>
  
  <p>There is a 5 character hex field in the object file, which I am creating from a value.</p>
  
  <p>Tried using: <code>String.format("%05X", decInt);</code></p>
  
  <p>This works as intended for positive numbers
  (11 -> <code>0000B</code>)
  However it fails for negative numbers
  (-1 -> <code>FFFFFFFF</code> instead of <code>FFFFF</code>)</p>
  
  <p>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.</p>