回答:
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"); } } |