aboutsummaryrefslogtreecommitdiff
path: root/number_1bits.cpp
blob: c8e0ac39af6115c5ad3cf475c282a9a5cb8a1f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "leetcode.h"

class Solution {
public:
  int hammingWeight(uint32_t n) {
    int count = 0;
    while (n > 0) {
      if ((n & 1) > 0)
        ++count;
      n = n >> 1;
    }
    return count;
  }
};

int main() {
  uint32_t n = 00000000000000000000000000001011;
  Solution obj;
  cout << obj.hammingWeight(n);
}