title: Guaranteeing negative result when left shifting a negative number in two's complement?
body: <p>Assuming a negative <a href="http://en.wikipedia.org/wiki/Binary_number" rel="noreferrer">binary number</a> is represented in <a href="http://en.wikipedia.org/wiki/Two&#39;s_complement" rel="noreferrer">two's complement</a>, <strong>how can we guarantee the sign is preserved?</strong></p>
  
  <p>Let's say we represent a decimal number <code>-5</code> in four bits: <code>1011</code>, and want to left-shift one place to multiply by 2:</p>
  
  <pre><code>1011 &lt;&lt; 1
  </code></pre>
  
  <p>This operation returns 0110, which is 6, <strong>not -10 as we would have hoped</strong>.</p>
  
  <p><em>(I assume this is only the case for negative numbers whose second bit is 0, ie negative numbers close to the smallest representable negative number of some range)</em></p>