title: Printing negative values as hex in python
body: <p>I have the following code snippet in C++:</p>
  
  <pre><code>for (int x = -4; x &lt; 5; ++x)
         printf("hex x %d 0x%08X\n", x, x);
  </code></pre>
  
  <p>And its output is </p>
  
  <pre><code>hex x -4 0xFFFFFFFC
  hex x -3 0xFFFFFFFD
  hex x -2 0xFFFFFFFE
  hex x -1 0xFFFFFFFF
  hex x 0 0x00000000
  hex x 1 0x00000001
  hex x 2 0x00000002
  hex x 3 0x00000003
  hex x 4 0x00000004
  </code></pre>
  
  <p>If I try the same thing in python:</p>
  
  <pre><code>for x in range(-4,5):
     print "hex x", x, hex(x)
  </code></pre>
  
  <p>I get the following</p>
  
  <pre><code>hex x -4 -0x4
  hex x -3 -0x3
  hex x -2 -0x2
  hex x -1 -0x1
  hex x 0 0x0
  hex x 1 0x1
  hex x 2 0x2
  hex x 3 0x3
  hex x 4 0x4
  </code></pre>
  
  <p>Or this:</p>
  
  <pre><code>for x in range(-4,5):
     print "hex x %d 0x%08X" % (x,x)
  </code></pre>
  
  <p>Which gives:</p>
  
  <pre><code>hex x -4 0x-0000004
  hex x -3 0x-0000003
  hex x -2 0x-0000002
  hex x -1 0x-0000001
  hex x 0 0x00000000
  hex x 1 0x00000001
  hex x 2 0x00000002
  hex x 3 0x00000003
  hex x 4 0x00000004
  </code></pre>
  
  <p>This is not what I expected. Is there some formatting trick I am missing that will turn -4 into 0xFFFFFFFC instead of -0x04?</p>