Table of Contents

Corning Community College

CSCS2330 Discrete Structures

~~TOC~~

Project: NUMBER BASE MANIPULATIONS (nbm0)

Objective

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.

base conversion

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.

Program

Your task is to write a program that:

Additional constraints:

Sample output is as follows:

Convert from base 8 to base 10

lab46:~/src/discrete/nbm0$ ./convert 8 31 10
25
lab46:~/src/discrete/nbm0$ 

Convert from base 9 to base 3

lab46:~/src/discrete/nbm0$ ./convert 9 8843 3
22221110
lab46:~/src/discrete/nbm0$ 

Convert from base 2 to base 16

lab46:~/src/discrete/nbm0$ ./convert 2 11010001 16
D1
lab46:~/src/discrete/nbm0$ 

Submission

Project Submission

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.

Submission Criteria

To be successful in this project, the following criteria must be met: