判断一个整数是否是2的N次幂及一个数是否是偶数

时间:2020-12-04 15:13:35
#include <stdio.h>


int main()
{

int n; 


scanf("%d", &n);


if(!(n&(n-1))) //is number  2^n?  1:no 0:yes
{
printf("this is number is 2^n!\n");
}else
{
printf("this is number is not 2^n!\n");
}


if((n & 0x1))  //is number 2*n
{
printf("this is number is odd\n");
}else
{
printf("this is number is even\n");
}


return 0;
}