Is it possilbe to reverse this piece of code to do the opposite? Right now it succesfully converts a hexadecimal number to a binary. How can I make it do the opposite? thanks.
Code:
int funcHexBin()/*function that converts hex to binary*/
{
char hex[] = "0123456789ABCDEF";
char *bin[] = { "0000", "0001", "0010", "0011", "0100", "0101",
"0110", "0111", "1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111" };
printf("Enter a Hexadecimal(use capital letters only): \n");
scanf("%s", &userhex2);
strl = strlen(&userhex2); /*get the length of the string*/
char *userhexd = &userhex2;
for (strl;strl>0;strl--)
{
printf("%s", bin[strchr(hex, *userhexd)-hex]);
userhexd++;
}
putchar('\n');
system("PAUSE");
return 0;
}