posts - 2,  comments - 0,  trackbacks - 0

#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 阅读(180) 评论(0)  编辑  收藏 所属分类: 数学&算法&数据结构

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(2)

文章分类(17)

文章档案(16)

收藏夹(17)

搜索

  •  

最新评论

阅读排行榜

评论排行榜