Number of 1 Bits

This is No.191 in LeetCode. This is the best solution I think, easy to understand and has a straight logic: public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int num_one = 0; //001000000010001 while( n > 0 ){ // 00010011 & 00000001 num_one += …