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 閱讀(190) 評論(0)  編輯  收藏 所屬分類: 數學&算法&數據結構
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(2)

          文章分類(17)

          文章檔案(16)

          收藏夾(17)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 汽车| 常熟市| 永春县| 遂宁市| 高唐县| 莫力| 醴陵市| 梅河口市| 汪清县| 潜山县| 宜昌市| 花垣县| 弥渡县| 公主岭市| 宿迁市| 永平县| 江安县| 阿城市| 武胜县| 东阳市| 榆林市| 乐陵市| 潼关县| 绩溪县| 攀枝花市| 磐石市| 进贤县| 贵港市| 习水县| 彭阳县| 阿坝| 微博| 万全县| 城市| 怀来县| 出国| 襄汾县| 开封县| 舟山市| 三明市| 大名县|