写一个函数返回参数二进制中 1 的个数 比如: 15 0000 1111 4 个 1 程序原型: int count_one_bits(unsigned int value) { //

来源:互联网 发布:depthmap软件原理 编辑:程序博客网 时间:2024/05/29 11:40
#include<stdio.h>int count_one_bit(int n){int count=0;while(n){n=n&(n-1);count++;}return count;}int main(){     int n=-1;     int count=count_one_bit(n);     printf("%d\n",count);system("pause");return 0;}

阅读全文
0 0
原创粉丝点击