hey,
first of all am new to C programming ! am trying to write a program that changes a binary 8 or 16 bit number into hex, i used to the select case in my program, my question is how can i make it recognise the whole 8/16 digit binary number i enter and not only the 4 bits that are identified in the look up table.. thank you
Code:#include <stdio.h> int main (); void bintohex (int); int main ()s { int digit; scanf ("%d", &digit); bintohex (digit); return 0; } void bintohex (int digit) /* print out bintohex code */ { switch (digit) { case 0000 : printf ("0"); break; case 0001 : printf ("1"); break; case 0010 : printf ("2"); break; case 0011 : printf ("3"); break; case 0100 : printf ("4"); break; case 0101 : printf ("5"); break; case 0110 : printf ("6"); break; case 0111 : printf ("7"); break; case 1000 : printf ("8"); break; case 1001 : printf ("9"); break; case 1010 : printf ("A"); break; case 1011 : printf ("B"); break; case 1100 : printf ("C"); break; case 1101 : printf ("D"); break; case 1110 : printf ("E"); break; case 1111 : printf ("F"); break; } printf ("\n\n"); }