判断一个数是否为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
", IS2N(0)); 
	printf("IS2N(1) == %d
", IS2N(1)); 
	printf("IS2N(2) == %d
", IS2N(2)); 
	printf("IS2N(3) == %d
", IS2N(3)); 
	printf("IS2N(4) == %d
", IS2N(4)); 
	printf("IS2N(5) == %d
", IS2N(5)); 
	printf("IS2N(12222) == %d
", IS2N(12222)); 
	printf("IS2N(124) == %d
", IS2N(124)); 
	printf("IS2N(512) == %d
", 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 . . .
*/
原文地址:https://www.cnblogs.com/mylinux/p/4630204.html