Corning Community College
CSCS2330 Discrete Structures
To apply your skills in crafting and deploying an algorithm that will enable you to convert a value from a source base to a destination base.
Number representation, as we first learned it, revealed a beautiful system of places with various weight values. Each place can increment or decrement its available counting digits until we reach either end of our range, then we “roll over”. In the case of addition, our highest counting digit rolls over to our lowest one, and we carry a one over to the next highest weighted place value.
What counting values are available depend on the numeric base we are operating within; base 10 (decimal) gives us ten unique counting digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Base 5 gives us five unique counting digits: 0, 1, 2, 3, 4.
Base 12 gives us twelve unique counting digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B.
The standard convention used once we exceed base 10 is to start utilizing the letters of the alphabet.
In this manner, we can easily interact with bases 2-36 (10 number digits, 26 alphabet letters, 10+26 = 36); we omit the non-sensical bases of 0 and 1 as a matter of course.
Converting between bases, we need to preserve the stored value, while adapting it to the new quantity of counting digits.
Your task is to write a program that:
Additional constraints:
Sample output is as follows:
lab46:~/src/discrete/nbm0$ ./convert 8 31 10 25 lab46:~/src/discrete/nbm0$
lab46:~/src/discrete/nbm0$ ./convert 9 8843 3 22221110 lab46:~/src/discrete/nbm0$
lab46:~/src/discrete/nbm0$ ./convert 2 11010001 16 D1 lab46:~/src/discrete/nbm0$
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
lab46:~/src/discrete/nbm0$ submit discrete nbm0 convert.c Submitting discrete project "nbm0": -> convert.c(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
To be successful in this project, the following criteria must be met: