I need to write a C functions that takes in uppercase hexade

I need to write a C function(s) that takes in uppercase hexadecimal values (between 3 to 40 characters long) prints them and then converts those values to the binary equivalent. For example if I input D2B, then the output should be \"Hex: D2B\" and \"Binary: 1101 0010 1011\". Note: The function is taking in command-line arguments NOT user input.

Solution

void main(int argc, char * argv[])
{   

char binarynum[MAX], hexa[MAX];
long int i = 0;

printf(\"Enter the value for hexadecimal \");

hexa = atoi(argc[1]);
printf(\"\ Equivalent binary value: \");
hexa = *argv[3];
while (hexa[i])
{
switch (hexa[i])
{
case \'0\':
printf(\"0000\"); break;
case \'1\':
printf(\"0001\"); break;
case \'2\':
printf(\"0010\"); break;
case \'3\':
printf(\"0011\"); break;
case \'4\':
printf(\"0100\"); break;
case \'5\':
printf(\"0101\"); break;
case \'6\':
printf(\"0110\"); break;
case \'7\':
printf(\"0111\"); break;
case \'8\':
printf(\"1000\"); break;
case \'9\':
printf(\"1001\"); break;
case \'A\':
printf(\"1010\"); break;
case \'B\':
printf(\"1011\"); break;
case \'C\':
printf(\"1100\"); break;
case \'D\':
printf(\"1101\"); break;
case \'E\':
printf(\"1110\"); break;
case \'F\':
printf(\"1111\"); break;
case \'a\':
printf(\"1010\"); break;
case \'b\':
printf(\"1011\"); break;
case \'c\':
printf(\"1100\"); break;
case \'d\':
printf(\"1101\"); break;
case \'e\':
printf(\"1110\"); break;
case \'f\':
printf(\"1111\"); break;
default:
printf(\"\ Invalid hexa digit %c \", hexa[i]);
return 0;
}
i++;
}
return 0;
}


default:
printf(\"Enter a valid choice\");
}
printf(\"\ The result of the operation is %d\", result);
printf(\"\ \");

I need to write a C function(s) that takes in uppercase hexadecimal values (between 3 to 40 characters long) prints them and then converts those values to the b
I need to write a C function(s) that takes in uppercase hexadecimal values (between 3 to 40 characters long) prints them and then converts those values to the b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site