title: Computing Hamming weight, also called popcount in Java?
body: <p>I am not sure how to translate this from C++ to Java.
  It is a function that computes the Hamming weight.</p>
  
  <pre><code>/** This is popcount_3() from:
   * http://en.wikipedia.org/wiki/Hamming_weight */
  unsigned int popcnt32(uint32_t n) const
  {
      n -= ((n &gt;&gt; 1) &amp; 0x55555555);
      n = (n &amp; 0x33333333) + ((n &gt;&gt; 2) &amp; 0x33333333);
      return (((n + (n &gt;&gt; 4))&amp; 0xF0F0F0F)* 0x1010101) &gt;&gt; 24;
  }
  </code></pre>
  
  <p>More concretely, I don't know what to use instead of uint32_t,
  and if I use that type whatever it is, can I just leave the rest
  code unchanged?</p>
  
  <p>Thanks</p>