title: Explain how typecasting works at the bit level from int to short in C
body: <p>If the binary representation of 2^31-1 is 01111111 11111111 11111111 11111111, what happens to that binary number when typecast to short?  This is assuming an int is 4 bytes, and a short is 2 bytes.</p>
  
  <p>I wrote a test program, and the output is -1 when typecast to short.  Is this correct?  Does this mean that typecast to short just chopped off the 16 most-significant bits, leaving 11111111 11111111 (signed 2's complement)?</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void main()
  {
          int x = sizeof(int);
          int y = sizeof(short);
          printf("%d, %d",x,y);
  
          int a = 2147483647;
          short b = (short)a;
  
          printf("\nad: %d",(int)a);
          printf("\nax: %x",(int)a);
          printf("\nau: %u",(int)a);
  
          printf("\nbd: %d",(int)b);
          printf("\nbx: %x",(int)b);
          printf("\nbu: %u",(int)b);
          printf("\n");
  }
  </code></pre>
  
  <p><strong>OUTPUT</strong></p>
  
  <pre><code>4, 2
  ad: 2147483647
  ax: 7fffffff
  au: 2147483647
  bd: -1
  bx: ffffffff
  bu: 4294967295
  </code></pre>