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("计算a^b: %d\n",a^b); printf("计算~a: %d\n",~a); printf("计算a<<b: %d\n",a<<b); printf("计算a>>b: %d\n",a>>b); printf("计算a|b: %d\n",a|b); }
求m*2^n
#include<iostream> #include<string.h> #include<stdio.h> #include<ctype.h> #include<algorithm> #include<stack> #include<queue> #include<math.h> using namespace std; int f(int m,int n) { return m<<n; } int main() { int m,n; while(scanf("%d%d",&m,&n)!=EOF) { int w=f(m,n); printf("%d\n",w); } return 0; }