写一个函数,返回二进制中1的个数
2016-05-05 11:49
176 查看
//写一个函数,返回二进制中1的个数 #include<stdio.h> #include<stdlib.h> int count_one_bit(unsigned int i) { int count = 0; while (i) { ++count; i = i >> 1; } return count; } int main() { int ret=count_one_bit(15); printf("%d\n", ret); system("pause"); return 0; }
相关文章推荐
- 【自考总结—16年4.17】
- LeetCode 276. Paint Fence
- Cause: java.sql.SQLException: 无法转换为内部表示
- Android Action
- c++实验五-数组分离
- c++实验5-数组分离
- 集群监控
- 关于MySql中自增长id设置初始值
- MarshalAs的使用
- 括号所有有效组合
- php遍历解析xml字符串的方法
- ajax学习笔记(一)
- 系统架构设计——设计模式之装饰者模式
- Spring+SpringMVC+MyBaties问题总结(二
- 安装java和hadoop的过程以及配置环境变量
- c++实验5—数组分离
- 大数据学习资源汇总
- linux系统LNMP环境下修改MYSQL数据库密码的方法
- linux cpufreq framework(3)_cpufreq core
- 银行卡验证代码交流