题目:Power of Two Given an integer, write a function to determine if it is a power of two. 题意:判断一个数是否是2的k次方数. 思路: 2的次方数使用2进制表示则必然只有最高位是1其他都是0: 这样判断一个数最多需要循环32次就能得出结果. 则程序如下: bool isPowerOfTwo(int n){ if (!n)return false; while ((n&0x01) != 0x01){//2的次方…
的幂 boolean power2(int x) { return((x&(x-1))==0)&&(x!=0): } For example: #include<stdio.h> int main() { printf(" *******int a=2; int b=3**********\n;"); int a=2; int b=3; printf("计算a&b: %d\n",a&b); printf("…