C++简洁代码:
求int型正整数在内存中存储时1的个数
http://www.nowcoder.com/questionTerminal/440f16e490a0404786865e99c6ad91c9
C++简洁代码:
#include<bits/stdc++.h> using namespace std; int main () { int n, res = 0; cin >> n; while(n) { if(n % 2) res ++; n >>= 1; } cout << res << endl; return 0; }