translate binary
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> int main(void) { unsigned short int inputDecimal = 0; unsigned int loop = 0, count = 0; unsigned char binary[16] = {0, }; scanf("%d", &inputDecimal); for (loop = 1; loop < 65537; loop*=2) { if (inputDecimal & loop) { binary[count] = '1'; } else binary[count] = '0'; count++; } for (loop = 15; loop >= 0; loop--) { printf("%c", binary[loop]); if (!(loop % 4)) printf(" "); } return 0; } | cs |
0 개의 댓글:
댓글 쓰기