#include<iostream> #include<stdint.h> using namespace std; class Solution { public: int hammingWeight(uint32_t n) { int count = 0; while (n){ n &= (n - 1);//见http://blog.csdn.net/ruan875417/article/details/43018069 ++count; } return count; } }; int main(){ Solution solution; cout << solution.hammingWeight(11) << endl; system("pause"); return 0; }