判断 一个数是不是 4 的幂

class Solution 
{
public:
    bool isPowerOfFour(int num) 
    {
        if(num<=0)
        return false;
        else
        {
            int test = 0x55555555;
            int MaxPowerOfFour = 0x01<<30;
            return MaxPowerOfFour % num ? false:((test&num)==num?true:false);
        }
    }
};

 

posted @ 2016-05-31 20:47  _in_the_way  阅读(383)  评论(0编辑  收藏  举报