title: Hexadecimal representation of a negative signed 8-bit integer
body: <p>In a portion of my program, I'll have to manage signed 8-bit integers. I have no problem to display them as decimals using <code>printf</code> and <code>%d</code> formatting.</p>
  <p>However, when it comes to hexadecimal representation, the formatting of a negative <code>int8_t</code> variable is not shown as a 8-bit hexadecimal (<code>0xXX</code>) but as a <strong>32-bit</strong> hexadecimal (<code>0xFFFFFFXX</code>).</p>
  <p>Here is the snippet of code, describing my problem:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  
  int main()
  {
      int8_t value = 0;
      
      printf(&quot;t = %d = 0x%02X\n&quot;, value, value);
      t = 127;
      printf(&quot;t = %d = 0x%02X\n&quot;, value, value);
      t = -128;
      printf(&quot;t = %d = 0x%02X\n&quot;, value, value);
      
      return 0;
  }
  </code></pre>
  <p>Compilation and execution give:</p>
  <pre class="lang-none prettyprint-override"><code>t = 0 = 0x00
  t = 127 = 0x7F
  t = -128 = 0xFFFFFF80
  </code></pre>
  <p>I would like to get <code>0x80</code> and not <code>0xFFFFFF80</code>. What did I do wrong? How to display the negative signed 8-bit integer as a 8-bit hexadecimal?</p>