// 判断一个数的二进制形式是否只有一个1,是的话就输出#include "stdafx.h"#include <stdlib.h>int main(int argc, char* argv[]){unsigned int n = 0;char str[100] = {0};do{if(n && (n & (n-1)) == 0){printf("%d, %X\n", n, n);}}while(++n <= 10000);return 0;}
运行结果:
1, 12, 24, 48, 816, 1032, 2064, 40128, 80256, 100512, 2001024, 4002048, 8004096, 10008192, 2000Press any key to continue