16,548
社区成员




#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int a = 0x12345678;
int length = sizeof(a) * 8;
int count = 0;
for ( int i = 0; i < length; i++)
{
if(a & 1)
count++;
a >>= 1;
}
cout << count << endl;
return 0;
}
#include <iostream>
#include <bitset>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string str = "1101";
bitset<32> bit(str);
cout<<bit.count()<<endl;
return 0;
}
int main(int argc, char* argv[])
{
int t = 0x11223344;
int i;
i = 0;
while( t )
{
t = t & ( t - 1 );
i++;
}
printf( "%d", i );
return 0;
}