All right. So I'm taking an assembly language class, but we apparently also need to use a smattering of Unix and C. Our assignment is to create a function that converts from the input base to a listed base.
Example of a call: ConvertToBase(057,10) should return 47 (the input was in octo, and decimal was requested).
The "easy" part is that this isn't an interactive program. I simply need to create the function and have the program use the function on a few numbers (using a UNIX typescript to show that it's a program that works and not just spitting out what i tell it to).
I understand that I need to create an array with all the characters I need, so:
char baseChar[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
I *THINK* this should work to convert the value:
while (inputInt != 0)
{
convertedInt[index] = inputInt % baseInt;
inputInt = inputInt / baseInt;
++index;
}
and then I *THINK* something like this would print the values in reverse order to the desired base
--index;
printf("\n\nConverted Number = ");
for( ; index>=0; index--)
{
printf("%c", baseChar[convertedInt[index]]);
}
printf("\n");
Unfortunately, this doesn't really seem to lend itself to a function. It's frustrating because I think I can write a program that does what I need, but I can't really make a function to do it. Can anyone help me out?