title: count Number of 1 Bits in java
body: <p>I encountered a strange problem while doing an leetcode problem. This is about bits representation in Java.</p>
  <blockquote>
  <p>Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).</p>
  <p>For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.</p>
  </blockquote>
  <p>My solution is</p>
  <pre><code>public class Solution {
  // you need to treat n as an unsigned value
      public int hammingWeight(int n) {
          int count = 0;
          for(int i = 0; i &lt; 32; ++i){
              if((n &gt;&gt;&gt; i) % 2 == 1){
                  ++count;
              }
          }
          return count;
      }
  }
  </code></pre>
  <p>This code is not accepted because of the input case:</p>
  <p>4294967295 (11111111111111111111111111111111)</p>
  <p>I reviewed the bit representation of integer in java but still do not know the problem of the solution? Could anyone help me?</p>