7 怎样检查一个数字是不是2的乘方

        bool result = false;

        result = CheckPowerOfTwo(8);
        Console.WriteLine(result.ToString());
            
            
        static bool CheckPowerOfTwo(ulong number)
        {
            return (number != 0) && ((number & (number - 1)) == 0);
        }


posted on 2017-05-18 08:38  ljbguanli  阅读(123)  评论(0编辑  收藏  举报