可能重复: 如何检查数字是2的幂
如果传入值2,4,8,32,64等,我怎么能写一个返回true的方法?
这可能是最好的方法:
((value & -value) == value)
如果你需要一个快速的算法,可能想看看这个:
http://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_check_if_a_positive_number_is_a_power_of_two