a*x
2 楼
Determining if an integer is a power of 2
unsigned int v; // we want to see if v is a power of 2
bool f; // the result goes here
f = (v & (v - 1)) == 0;
Note that 0 is incorrectly considered a power of 2 here. To remedy this, use:
f = !(v & (v - 1)) && v;
【在 x**d 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: 如何用一句语句判断一个数是否是power of 2?(2的指数幂)
: 从网上看到的,想了很久,没招。
: 哪个牛人给说说?
unsigned int v; // we want to see if v is a power of 2
bool f; // the result goes here
f = (v & (v - 1)) == 0;
Note that 0 is incorrectly considered a power of 2 here. To remedy this, use:
f = !(v & (v - 1)) && v;
【在 x**d 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: 如何用一句语句判断一个数是否是power of 2?(2的指数幂)
: 从网上看到的,想了很久,没招。
: 哪个牛人给说说?
相关阅读
如何理解回溯?c++ namespace求指教在excel里面怎么样call c++程序?问一个python调用awk得问题请推荐一本入门C#的书why still use hadoop when we have parallel programming from ms/intelRe: GooG的困局andriod 编程问题怎么在网页里加一個连接,自动连到用户的lotus notes,compose新的email,自动填入email address,subject,body content?学习学习国内的IT项目-12306铁道部订票网站性能分析【转载】 (转载)大家用jquery写网页的水平滑动slide, css和js文件是自己写的吗?如果以后打算创业的话,应该做些什么技术呢?前端?Getting Started with Storm关于web server对于web service的支持我说一句,感觉这里的人有些瞧不起国内的程序员本版现在主题就是战啊。。。Re: 学术:面向对象是这个意思吧 (转载)快速找工作的话学什么语言最好?json是一种革命性的创造搞技术的全是老中的公司,好吗?