Binary representation of each input hex integer Sample input

Binary representation of each input hex integer Sample input: 0x4 0xa015 Sample output: 0100 0000 0001 0101

Solution


#include <stdio.h>
#include <string.h>

int main()
{
int j=0;
char hexdecmal[17], bnary[65] = \"\";
printf(\"please enter hexadecimaL:: \");
gets(hexdecmal);

for(j=0; hexdecmal[j]!=\'\\0\'; j++)
{
switch(hexdecmal[j])
{
case \'a\':
case \'A\':
strcat(bnary, \"1010\");
break;
case \'b\':
case \'B\':
strcat(bnary, \"1011\");
break;
case \'c\':
case \'C\':
strcat(bnary, \"1100\");
break;
case \'d\':
case \'D\':
strcat(bnary, \"1101\");
break;
case \'e\':
case \'E\':
strcat(bnary, \"1110\");
break;
case \'f\':
case \'F\':
strcat(bnary, \"1111\");
break;
               case \'0\':
strcat(bnary, \"0000\");
break;
case \'1\':
strcat(bnary, \"0001\");
break;
case \'2\':
strcat(bnary, \"0010\");
break;
case \'3\':
strcat(bnary, \"0011\");
break;
case \'4\':
strcat(bnary, \"0100\");
break;
case \'5\':
strcat(bnary, \"0101\");
break;
case \'6\':
strcat(bnary, \"0110\");
break;
case \'7\':
strcat(bnary, \"0111\");
break;
case \'8\':
strcat(bnary, \"1000\");
break;
case \'9\':
strcat(bnary, \"1001\");
break;
  
}
}

printf(\"binary value is: %s\", bnary);

return 0;
}

output:

please enter hexadecimaL::0xa015

binary value is: 00001010000000010101

 Binary representation of each input hex integer Sample input: 0x4 0xa015 Sample output: 0100 0000 0001 0101 Solution #include <stdio.h> #include <stri
 Binary representation of each input hex integer Sample input: 0x4 0xa015 Sample output: 0100 0000 0001 0101 Solution #include <stdio.h> #include <stri

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site