title: How does C convert signed hex number to negative numbers?
body: <p>So recently, I met this problem:</p>
  
  <p>Given: int x; unsigned int y; x = 0xAB78; y = 0xAB78; write a program to display the decimal values of x and y on the screen.</p>
  
  <p>And here is the program I wrote: ( I am on a 64-bit windows 7 machine)</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  
  int main()
  {
      short int x;
      unsigned short int y;
      x = 0xAB78;
      y = 0xAB78;
      printf("The decimal values of x and y are: %d &amp; %hu.\n", x, y);
      return 0;
  }
  </code></pre>
  
  <p>The output I got is:
  x=-21640, and y=43896.</p>
  
  <p>I am ok with the unsigned hex number,
  since 0xAB78 = 10*16^3 + 11*16^2 + 7*16^1 + 8*16^0 = 43896.</p>
  
  <p>However for the signed hex number,
  should it be: -1*16^3 + 11*16^2 + 7*16^1 +8*16^0 = -1160?
  why is it -21640 then?</p>
  
  <p>Thank you for your time!</p>