How to determine whether a number is 2^[INTEGER]?
I have an idea: let we have “a” is the number to determine.
return ( (0 == (a & (a-1))) && (a > 0))
Despite the style of the code, is there some better solution? Note that a is a native integer type (say, int, long, long long, etc).
在线阅读本文并参与讨论 delphij's Chaos https://blog.delphij.net/posts/2005/05/how-to-determin/