User Tools

Site Tools


Sidebar

projects

  • dsi0 (due 20160831)
  • pnc0 (due 20160831)
  • wpf0 (due 20160831)
  • pnc1 (due 20160907)
  • wpf1 (due 20160907)
  • pnc2 (due 20160914)
  • wpf2 (due 20160914)
  • wpf3 (due 20160921)
  • dcf0 (due 20160921)
  • wpf4 (due 20160928)
  • dcf1 (due 20160928)
  • wpf5 (due 20161005)
  • dcf2 (due 20161019)
  • wpf6 (due 20161019)
  • wpf7 (due 20161026)
  • nbm0 (due 20161102)
  • wpf8 (due 20161102)
  • yol0 (due 20161111)
  • wpf9 (due 20161109)
  • smh0 (due 20161116)
  • wpfA (due 20161116)
  • wpfB (due 20161130)
  • wpfC (due 20161207) – bonus
  • wpfD (due 20161207) – bonus
  • EoCE (bottom of your journal) (due 20161216-105959)
haas:fall2016:discrete:projects:nbm0

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:

  • 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).
  • 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.

Additional constraints:

  • You are to implement the algoriths 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 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:

  • Project must be submit on time, by the posted deadline.
    • Early submissions will earn 1 bonus point per full day in advance of the deadline.
      • Bonus eligibility requires an honest attempt at performing the project (no blank efforts accepted)
    • Late submissions will lose 25% credit per day, with the submission window closing on the 4th day following the deadline.
      • To clarify: if a project is due on Wednesday (before its end), it would then be 25% off on Thursday, 50% off on Friday, 75% off on Saturday, and worth 0% once it becomes Sunday.
      • Certain projects may not have a late grace period, and the due date is the absolute end of things.
  • all requested functionality must conform to stated requirements (either on this project page or in comment banner in source code files themselves).
  • Output generated must conform to any provided requirements and specifications (be it in syntax or sample output)
    • output obviously must also be correct based on input.
  • Processing must be correct based on input given and output requested
  • Specification details are NOT to be altered. This project will be evaluated according to the specifications laid out in this document.
  • Code must compile cleanly.
    • Each source file must compile cleanly (worth 3 total points):
      • 3/3: no compiler warnings, notes or errors.
      • 2/3: one of warning or note present during compile
      • 1/3: two of warning or note present during compile
      • 0/3: compiler errors present (code doesn't compile)
  • Code must be nicely and consistently indented (you may use the indent tool)
    • You are free to use your own coding style, but you must be consistent
    • Avoid unnecessary blank lines (some are good for readability, but do not go overboard- double-spacing your code will get points deducted).
    • Indentation will be rated on the following scale (worth 3 total points):
      • 3/3: Aesthetically pleasing, pristine indentation, easy to read, organized
      • 2/3: Mostly consistent indentation, but some distractions (superfluous or lacking blank lines, or some sort of “busy” ness to the code)
      • 1/3: Some indentation issues, difficult to read
      • 0/3: Lack of consistent indentation (didn't appear to try)
  • Code must be commented
    • Commenting will be rated on the following scale (worth 3 total points):
      • 3/3: Aesthetically pleasing (comments aligned or generally not distracting), easy to read, organized
      • 2/3: Mostly consistent, some distractions or gaps in comments (not explaining important things)
      • 1/3: Light commenting effort, not much time or energy appears to have been put in.
      • 0/3: No original comments
      • should I deserve nice things, my terminal is usually 90 characters wide. So if you'd like to format your code not to exceed 90 character wide terminals (and avoid line wrapping comments), at least as reasonably as possible, those are two sure-fire ways of making a good impression on me with respect to code presentation and comments.
    • Sufficient comments explaining the point of provided logic MUST be present
  • Code must be appropriately modified
    • Appropriate modifications will be rated on the following scale (worth 3 total points):
      • 3/3: Complete attention to detail, original-looking implementation
      • 2/3: Lacking some details (like variable initializations), but otherwise complete (still conforms, or conforms mostly to specifications)
      • 1/3: Incomplete implementation (typically lacking some obvious details/does not conform to specifications)
      • 0/3: Incomplete implementation to the point of non-functionality (or was not started at all)
    • Implementation must be accurate with respect to the spirit/purpose of the project (if the focus is on exploring a certain algorithm to produce results, but you avoid the algorithm yet still produce the same results– that's what I'm talking about here).. worth 3 total points:
      • 3/3: Implementation is in line with spirit of project
      • 2/3: Some avoidance/shortcuts taken (note this does not mean optimization– you can optimize all you want, so long as it doesn't violate the spirit of the project).
      • 1/3: Generally avoiding the spirit of the project (new, different things, resorting to old and familiar, despite it being against the directions)
      • 0/3: entirely avoiding.
    • Error checking must be adequately and appropriately performed, according to the following scale (worth 3 total points):
      • 3/3: Full and proper error checking performed for all reasonable cases, including queries for external resources and data.
      • 2/3: Enough error checking performed to pass basic project requirements and work for most operational cases.
      • 1/3: Minimal error checking, code is fragile (code may not work in full accordance with project requirements)
      • 0/3: No error checking (code likely does not work in accordance with project requirements)
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool (make submit will do this) by the deadline.
haas/fall2016/discrete/projects/nbm0.txt · Last modified: 2016/10/24 19:52 by wedge