判断一个数是否为2的若干次幂

#include "stdafx.h"
#include <stdio.h>

#include "t5.h"

#define IS2N(x) (((x)&(x-1))?0:1)

int t6(void)
{
	bool y;

	printf("IS2N(0) == %d\n", IS2N(0)); 
	printf("IS2N(1) == %d\n", IS2N(1)); 
	printf("IS2N(2) == %d\n", IS2N(2)); 
	printf("IS2N(3) == %d\n", IS2N(3)); 
	printf("IS2N(4) == %d\n", IS2N(4)); 
	printf("IS2N(5) == %d\n", IS2N(5)); 
	printf("IS2N(12222) == %d\n", IS2N(12222)); 
	printf("IS2N(124) == %d\n", IS2N(124)); 
	printf("IS2N(512) == %d\n", IS2N(512)); 

	return 0;
}
/*
IS2N(0) == 1
IS2N(1) == 1
IS2N(2) == 1
IS2N(3) == 0
IS2N(4) == 1
IS2N(5) == 0
IS2N(12222) == 0
IS2N(124) == 0
IS2N(512) == 1
Press any key to continue . . .
*/

 

你可能感兴趣的:(判断)