// 判断一个数的二进制形式是否只有一个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, 1
2, 2
4, 4
8, 8
16, 10
32, 20
64, 40
128, 80
256, 100
512, 200
1024, 400
2048, 800
4096, 1000
8192, 2000
Press any key to continue