1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <stdio.h> void bit_pattern(int num) { for (int i = 7; i >= 0; i--) printf("%c", '0' + ((num >> i) & 0x1)); } void main() { int num; while (1) { printf("number(0-255) ? "); scanf("%d", &num); if (num < 0 || num > 255) return; bit_pattern(num); printf("\n"); } }