可能重複:
How to check if a number is a power of 2確定在java中num是否是2的冪次?
我怎麼能寫,如果的值傳遞2,4,8,32,64,等等都將返回true的方法?
可能重複:
How to check if a number is a power of 2確定在java中num是否是2的冪次?
我怎麼能寫,如果的值傳遞2,4,8,32,64,等等都將返回true的方法?
這可能是最好的辦法:
((value & -value) == value)
可能重複:http://stackoverflow.com/ q/600293/1048330 – tenorsax 2012-02-05 04:17:49
看到位扭曲的黑客(我敢肯定,這已被問以前在SO)...... – 2012-02-05 04:17:55
[你有什麼嘗試?](http://mattgemmell.com/2008/12/08 /你有什麼試過的/)這個功課是? – 2012-02-05 04:18:00