如何在C中以二进制格式打印十进制数?

回答:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

#define CHAR_BITS  8  // size of character

#define INT_BITS  ( sizeof(int) * CHAR_BITS) //bits in integer

void PrintInBinary(unsigned n)

{

char Pos = (INT_BITS -1);

for (; Pos >= 0 ; --Pos)

{

  (n & (1 << Pos))? printf("1"): printf("0");

}

}

原文地址:https://www.cnblogs.com/CodeWorkerLiMing/p/12007364.html