会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
InternetJava
博客园
首页
新随笔
联系
管理
订阅
2022年3月6日
正整数的二进制表示中1的个数计算(使用移位或者n&(n-1))
摘要: 第一种:使用n&(n-1)表示来计算有多少个1 int n=127; int count=0; while (n!=0){ count++; n=n&(n-1); } 第二种:使用移位操作 Integer input = in.nextInt(); int count=0; for(int i=0;
阅读全文
posted @ 2022-03-06 09:37 小小白兔兔
阅读(35)
评论(0)
推荐(0)
公告