判断一个数中二进制中1的个数

1.写一个函数返回参数二进制中 1 的个数 比如: 15 0000 1111 4 个 1 程序原型: int count_one_bits(unsigned int value) { 返回 1的位数 } int count_one_bits(n) { int count = 0; while (n) { n = n&(n - 1); count++; } printf("%d ", count);
相关文章
相关标签/搜索