#include #include #include #define BITMASK(n) (1 << (n)) void divide_and_print(int x){ printf("Dec: %d\n", x); printf("Hex: 0x%X\n", x); printf("Bin: "); int found_first_one = 0; int i = 31; for(i = 31; i >= 0; i--){ if(x&BITMASK(i)){ printf("1"); if(found_first_one == 0){ found_first_one = 1; } } else if(found_first_one){ printf("0"); } } printf("\n"); } int main(int argc, char *argv[]){ if(argc != 2){ printf("[Usage]: Input a valid Dec number\n"); return -1; } int x = atoi(argv[1]); divide_and_print(x); return 0; }