When an int is cast to a short and truncated, how is the new value determined?
<p>Can someone clarify what happens when an integer is cast to a <code>short</code> in C? I'm using Raspberry Pi, so I'm aware that an <code>int</code> is 32 bits, and therefore a <code>short</code> must be 16 bits.</p>

<p>Let's say I use the following C code for example:</p>

<pre><code>int x = 0x1248642;
short sx = (short)x;
int y = sx;
</code></pre>

<p>I get that <code>x</code> would be truncated, but can someone explain how exactly? Are shifts used? How exactly is a number truncated from 32 bits to 16 bits?</p>