title: why does bitwise shift replace date with 1s instead of 0 here?
body: <p>For a program utilising bitmasks I desired to write numbers in binary... i.e To copy the first 8 bits of <code>x</code> to <code>z</code>, I write </p>
  
  <pre><code>y = 0xff000000;
  z = 0;
  z = (y &amp; x) | z
  </code></pre>
  
  <p>Where <code>x, y, z</code> are all <code>int</code>. Now using <em>left shift</em> and <em>right shift</em> operators I wanted to move 1s of <code>y</code> right or left to bitmask another set of bits, so I write the following code</p>
  
  <pre><code>cout&lt;&lt; bitset&lt;32&gt;(y&gt;&gt;10) &lt;&lt;"\n" &lt;&lt; bitset&lt;32&gt;(y&lt;&lt;10) &lt;&lt;endl;
  </code></pre>
  
  <p>Now what I expected as output was:</p>
  
  <pre><code>00000000001111111100000000000000
  00000000000000000000000000000000
  </code></pre>
  
  <p>but I got:</p>
  
  <pre><code>11111111111111111100000000000000
  00000000000000000000000000000000
  </code></pre>
  
  <ol>
  <li>Why are the new bits '1' intead of '0' on first line of output?</li>
  <li>How can I change current output to desired output?</li>
  </ol>