user14374: How does arduino uno cast from long to int?
Does it truncate the bits? (Does it just delete the 16 most left bits?)

user4143: Yes, it just blindly chops off the upper 16 bits.  That means that the sign can change between the two.
For instance, 123456789 gets truncated to -13035 and -123456789 truncates to 13035.
To see that in more detail, look at the binary.  123456789 in binary is:
0000 0111 0101 1011 1100 1101 0001 0101

Truncate that at 16 bits and you get:
1100 1101 0001 0101

And of course the high (sign) bit is set, so the value is negative.

14374: <p>How does arduino uno cast from <strong>long</strong> to <strong>int</strong>?</p>

<p>Does it truncate the bits? (Does it just delete the 16 most left bits?)</p>
 4143: <p>Yes, it just blindly chops off the upper 16 bits.  That means that the sign can change between the two.</p>

<p>For instance, 123456789 gets truncated to -13035 and -123456789 truncates to 13035.</p>

<p>To see that in more detail, look at the binary.  123456789 in binary is:</p>

<pre><code>0000 0111 0101 1011 1100 1101 0001 0101
</code></pre>

<p>Truncate that at 16 bits and you get:</p>

<pre><code>1100 1101 0001 0101
</code></pre>

<p>And of course the high (sign) bit is set, so the value is negative.</p>
