首先是power of two, 然后奇数位是1的都不是,比如10, 1000
4 : 1(1), 4(100), 16(10000),
bool isPowerOfFour(int num) {
return num>0 && !(num&0xAAAAAAAA) && !(num&(num-1));
}
首先是power of two, 然后奇数位是1的都不是,比如10, 1000
4 : 1(1), 4(100), 16(10000),
bool isPowerOfFour(int num) {
return num>0 && !(num&0xAAAAAAAA) && !(num&(num-1));
}