Corning Community College
CSCS2330 Discrete Structures
======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.
=====number bases=====
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:
* accepts (via command-line arguments), 3 pieces of information:
* argv[1]: input base (represented from the point of view of base 10)
* base can be any from range of 2-36 (inclusive)
* argv[2]: input value (represented in the indicated input base)
* argv[3]: output base (represented from the point of view of base 10)
* base can be any from range of 2-36 (inclusive)
* on invalid base (< 2 or > 36, display an error to STDERR and exit with non-zero value).
* converts those values into processable numeric values
* if input value contains invalid counting digits for base, display an error to STDERR and exit.
* converts the input value (informed by the input base) to the output value (in output base)
* displays the output value to STDOUT, followed by a single newline.
* Make sure your program ONLY displays the converted value to STDOUT- we will use this for output validation purposes.
* program then exits, returning 0 on successful execution.
====Restrictions====
Additional constraints:
* You are to implement the algorithms to convert to/from various bases. As such:
* no printf()/scanf()-family format conversion shortcuts
* no strtoul()-family base processing shortcuts
* use only numeric digits 0-9 and uppercase letters A-Z for number representations
* you may assume ONLY unsigned values, no negatives
* you may assume a MAXIMUM quantity of 2^64 (basically what can be stored in an **unsigned long long int**), aka 8 bytes for packed data, up to 64 bytes for per-digit binary values.
=====Sample Output=====
Sample output is as follows:
===Convert from base 8 to base 10===
lab46:~/src/discrete/nbm0$ ./nbm0 8 31 10
25
lab46:~/src/discrete/nbm0$
===Convert from base 9 to base 3===
lab46:~/src/discrete/nbm0$ ./nbm0 9 8843 3
22221110
lab46:~/src/discrete/nbm0$
===Convert from base 2 to base 16===
lab46:~/src/discrete/nbm0$ ./nbm0 2 11010001 16
D1
lab46:~/src/discrete/nbm0$
=====Submission=====
=====Submission=====
To successfully complete this project, the following criteria must be met:
* Code must compile cleanly (no warnings or errors)
* Use the **-Wall** and **--std=gnu99** flags when compiling (which occurs automatically when using **make**).
* Code must be nicely and consistently indented (you may use the **indent** tool)
* Code must utilize the algorithm/approach presented above
* Implementation must be free from stated restrictions above
* Output **must** match the specifications presented above (when given the same inputs)
* Code must be commented
* be sure your comments reflect the **how** and **why** of what you are doing, not merely the **what**.
* Track/version the source code in a repository
* Submit a copy of your source code to me by running **make submit**
To submit this program to me using the Makefile tool (**make submit**), run the following:
lab46:~/src/discrete/nbm0$ make submit
removed ‘nbm0’
removed ‘errors’
Project backup process commencing
Taking snapshot of current project (nbm0) ... OK
Compressing snapshot of nbm0 project archive ... OK
Setting secure permissions on nbm0 archive ... OK
Project backup process complete
Submitting discrete project "nbm0":
-> ../nbm0-YYYYMMDD-HH.tar.gz(OK)
SUCCESSFULLY SUBMITTED
lab46:~/src/discrete/nbm0$
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.
=====Evaluation Criteria=====
What I will be looking for:
104:nbm0:final tally of results (104/104)
*:nbm0:submitted file called nbm0.c [5/5]
*:nbm0:adequate indentation [8/8]
*:nbm0:sufficient comments [8/8]
*:nbm0:adequate error checking [13/13]
*:nbm0:adequate modifications [13/13]
*:nbm0:commit and pushed to repo [5/5]
*:nbm0:clean compilation [13/13]
*:nbm0:runtime tests succeed [39/39]
Additionally:
* Solutions not abiding by spirit of project will be subject to a 25% overall deduction
* Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
* Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction
* Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction