title: C strange behaviour when bit-shifting
body: <p>Why the following code, compiled with gcc, prints "ffffffff 0" instead of "0 0"? The bits are shifted to the right by 32 positions in both instructions. It doesn't make much sense, since x == 32, but still this strange result happens...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      int x = 32;
      printf("%x\n", 0xffffffff &gt;&gt; x);
      printf("%x\n", 0xffffffff &gt;&gt; 32);
      return 0;
  }
  </code></pre>
  
  <p>Edit:
  <a href="https://i.stack.imgur.com/PgufY.png" rel="nofollow"><img src="https://i.stack.imgur.com/PgufY.png" alt="enter image description here"></a></p>
  
  <p>Edit2:
     Yes, the compiler warned me. But this is not the point. I am using 0xffffffff as a mask that I bitshift with a variable. For example, when I bitshift with 8 I want 0xffffff (and it does that). When I bitshift with 31 I want 0x1 as a result (and it does that). And when I bitshift with 32 it gives me 0xffffffff (instead of 0, which is the beahaviour when I have 32 as a literal, not a variable). It is strange and for my purpose it is really unconvenient to make a special case for 32 since it should give 0 (and it does, but only when 32 is a literal)</p>