User Tools

Site Tools


Sidebar

projects

wcp1 (due 20220824)
ntr0 (due 20220831)
pct1 (bonus; due 20220831)
uom0 (due 20220831)
wcp2 (due 20220831)
pct2 (due 20220907)
pct3 (bonus; due 20220907)
rle0 (due 20220907)
wcp3 (due 20220907)
bdb0 (due 20220914)
wcp4 (due 20220914)
pct4 (due 20220915)
cnv0 (due 20220921)
wcp5 (due 20220921)
pct5 (bonus; due 20220922)
gfo0 (due 20220928)
lmr0 (due 20220928)
wcp6 (due 20220928)
pct6 (due 20220929)
pct7 (bonus; due 20221005)
rle1 (due 20221005)
wcp7 (due 20221005)
bwp1 (bonus; due 20221019)
pct8 (due 20221019)
wcp8 (due 20221019)
cnv1 (due 20221020)
pct9 (bonus; due 20221026)
wcp9 (due 20221026)
lmr1 (due 20221027)
gfo1 (due 20221102)
pctA (due 20221102)
wcpA (due 20221102)
rle2 (due 20221104)
pctB (bonus; due 20221109)
wcpB (due 20221109)
cnv2 (due 20221110)
pctC (due 20221116)
wcpC (due 20221116)
lmr2 (due 20221117)
bwp2 (bonus; due 20221201)
pctD (bonus; due 20221201)
wcpD (bonus; due 20221201)
pctE (bonus; due 20221207)
wcpE (bonus; due 20221207)
gfo2 (due 20221208)
EoCE (due 20221219)
haas:fall2022:discrete:projects:nbm0

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:

130:nbm0:final tally of results (130/130)
*:nbm0:submitted file called nbm0.c [13/13]
*:nbm0:adequate, consistent indentation [13/13]
*:nbm0:adequate, sufficient why/how comments [13/13]
*:nbm0:adequate error checking [13/13]
*:nbm0:adequate modifications [13/13]
*:nbm0:commit and pushed to repo [13/13]
*:nbm0:clean compilation, no warnings/errors [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
haas/fall2022/discrete/projects/nbm0.txt · Last modified: 2020/10/16 13:04 by 127.0.0.1