title: can't shift negative numbers to the right in c
body: <p>I am going through 'The C language by K&amp;R'. Right now I am doing the bitwise section. I am having a hard time in understanding the following code.</p>
  
  <pre><code>int mask = ~0 &gt;&gt; n;
  </code></pre>
  
  <p>I was playing on using this to mask n left side of another binary like this.
      0000 1111
      1010 0101 // random number</p>
  
  <p>My problem is that when I print var mask it still negative -1. Assuming n is 4. I thought shifting ~0 which is -1 will be 15 (0000 1111).</p>
  
  <p>thanks for the answers</p>