#include<stdio.h>
#include<stdlib.h>
unsigned long count_one(unsigned long data)
{
unsigned long count = 0;
unsigned long x = data;
while(x)
{
count++;
x = x & (x-1);
}
return count;
}
int main(){
unsigned long data[] = {13,16,25,31,76};
int i = 0;
int size = sizeof(data)/sizeof(unsigned long);
for(i=0;i<size;i++){
printf("%d has %d 1s\n",data[i],count_one(data[i]));
}
return 0;
}
posted on 2009-07-19 14:38
iConnect 阅读(185)
评论(0) 编辑 收藏 所属分类:
数学&算法&数据结构