<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p>Yes, an odorous rodent, with an itch head.</p>
<p>Part 2:</p>
<p>$ cat check.c<br />#include <stdio.h></p>
<p>int main(int argc, char *argv[])<br />{<br />  /* unsigned int is 32 bits */<br />  unsigned int a,b;<br />  unsigned int n0 = 24, n1 = 10;</p>
<p>  a = 0xFFFFFFFF;<br />  a = a << (n0+n1);</p>
<p>  b = 0xFFFFFFFF;<br />  b = (b << n0) << n1;</p>
<p>  printf("%08X should equal %08X\n", a, b);<br />  return 0;<br />}</p>
<p>Both 'a' and 'b' are shifted right by a total of 34 bits.</p>
<p>$ gcc -o check check.c -Wall -pedantic<br />$ ./check<br />FFFFFFFC should equal 00000000</p>
<p>It gives different answers depending on optimizations, and no warnings!</p>
<p>$ gcc -o check check.c -Wall -pedantic -O4<br />$ ./check<br />00000000 should equal 00000000<br />$</p>
<p>After 80286, Intel  behavior is to mask the shift count by 0x1F, for 32-bit values.</p>
<p>Mike</p>
<p>On 26.04.2017 11:00, Charles Manning wrote:</p>
<blockquote style="padding-left: 5px; border-left: #1010ff  2px  solid; margin-left: 5px; width: 100%;">
<div dir="ltr">
<div>It depends.... the ultimate weasel answer :-).<br /><br /></div>
I get a compilation error because I always compile with -Wall -Werror. SInce everyone should be doing that (my decree) that is the ultimate answer.<br />
<div><br />gcc bigshift.c -o bigshift -Wall -Werror<br />bigshift.c: In function ‘main’:<br />bigshift.c:5:29: error: left shift count >= width of type [-Werror=shift-count-overflow]<br />   printf("%d\n", 0xFFFFFFFF << 34);<br />                             ^<br />cc1: all warnings being treated as errors<br /><br /></div>
</div>
<div class="gmail_extra"><br />
<div class="gmail_quote">On Wed, Apr 26, 2017 at 10:52 AM, Mark Atherton <span><<a href="mailto:markaren1@xtra.co.nz">markaren1@xtra.co.nz</a>></span> wrote:<br />
<blockquote class="gmail_quote" style="margin: 0   0   0   .8ex; border-left: 1px   #ccc   solid; padding-left: 1ex;"><span style="text-decoration: underline;"></span>
<div>Doesn't it depend on what 'a' is declared as, and the language ?<br /><br />Assuming C, and if 'a' was a U32, and 0xFFFFFFFF was 0xFFFFFFFFL, and 34 was 34L, then possibly the answer might, perhaps, possibly be 0.<br /><br />having said that, given the context of the question and the person asking the question, I smell an odorous rodent :)<br /><br />-Mark<br /><br /><a href="http://www.c4learn.com/c-programming/c-bitwise-left-shift-operator/">http://www.c4learn.com/c-programming/c-bitwise-left-shift-operator/</a>ties up with my understanding, but again I may need more anti-paranoia medication...
<div>
<div class="h5"><br /><br />
<blockquote style="padding-left: 5px; border-left: #1010ff  2px  solid; margin-left: 5px; width: 100%;">On 26 April 2017 at 10:04 hamster <<a href="mailto:hamster@snap.net.nz">hamster@snap.net.nz</a>> wrote:<br /><br />
<p>Sorry - no chocolate fish this time</p>
<p>What is the value of a?</p>
<p>  a = 0xFFFFFFFF << 34;</p>
<p>Have you checked your answer?</p>
<p> </p>
<p> </p>
<div> </div>
</blockquote>
<br /> </div>
</div>
<blockquote style="padding-left: 5px; border-left: #1010ff  2px  solid; margin-left: 5px; width: 100%;">_______________________________________________<br />Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.linuxnut.co.nz">Chchrobotics@lists.linuxnut.co.nz</a><br /><a href="http://lists.ourshack.com/mailman/listinfo/chchrobotics">http://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br />Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/">http://lists.ourshack.com/pipermail/chchrobotics/</a><br />Meetings usually 3rd Monday each month. See <a href="http://kiwibots.org">http://kiwibots.org</a> for venue, directions and dates.<br />When replying, please edit your Subject line to reflect new subjects.</blockquote>
<br /> </div>
<br />_______________________________________________<br /> Chchrobotics mailing list <a href="mailto:Chchrobotics@lists.linuxnut.co.nz">Chchrobotics@lists.linuxnut.co.nz</a><br /><a href="http://lists.ourshack.com/mailman/listinfo/chchrobotics">http://lists.ourshack.com/mailman/listinfo/chchrobotics</a><br /> Mail Archives: <a href="http://lists.ourshack.com/pipermail/chchrobotics/">http://lists.ourshack.com/pipermail/chchrobotics/</a><br /> Meetings usually 3rd Monday each month. See <a href="http://kiwibots.org">http://kiwibots.org</a> for venue, directions and dates.<br /> When replying, please edit your Subject line to reflect new subjects.</blockquote>
</div>
</div>
</blockquote>
<p> </p>
<div> </div>
<div> </div>
</body></html>