判断一个整数是不是 2 的幂 , 对于一个数 x >= 0 ,判断他是不是 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********** ;"); int a=2; int b=3; printf("计算a&b: %d ",a&b); printf("计算a^b: %d ",a^b); printf("计算~a: %d ",~a); printf("计算a<<b: %d ",a<<b); printf("计算a>>b: %d ",a>>b); printf("计算a|b: %d ",a|b); }