count the the number of 1s in its binary representation -- shift right don't work?
<p>when asked the question to count the number of 1s in the binary representation , the first answer came to my mind is to shift the number right and count the least important bit</p>

<p>but there is a saying that when the number is negative , this method will cause infinite loop ?</p>

<p>I tried quickly with python</p>

<pre><code>&gt;&gt;&gt; a = -16
&gt;&gt;&gt; a &gt;&gt; 1
-8
&gt;&gt;&gt; a &gt;&gt; 1
-8
&gt;&gt;&gt; -8 &gt;&gt; 1
-4
&gt;&gt;&gt;
</code></pre>

<p>this is what I expect, so what is the issue, will shift the negative number cause the sign bit to be carried over to the right ?</p>
