Projects‎ > ‎

Project01

Number Converter Command Line Utility

Due Tuesday, September 13th 2016 at 11:59pm in your Github repository for Project01

Project01 will be a short warm up project to get you into C programming and to get you familiar with number representations. You will implement a UNIX command line program, called ncc, in C that can convert values between different number systems. This little utility may prove useful for future projects.

Here is how it looks when you execute it with different values.

$ ncc 713
713 (base 10)  0010 1100 1001 (base 2)  0b001011001001 (base 2) 0x2C9 (base 16)

Note that ncc detects that 713 is a decimal number (more later). It then outputs the equivalent binary and the hexadecimal values. You need to output binary values in two forms: separate groups of 4 bits and a single number prefixed with 0b.

$ ncc -713
-713 (base 10) 1101 0011 0111 (base 2)  0b110100110111 (base 2) 0xD37 (base 16)

Note we get the binary and hexadecimal versions of the 2's complement representation of -713

$ ncc 0b11100011
0b11100011 (base 2)  227 (base 10)  -29 (base 10 signed)  0xE3 (base 16)

In this case, ncc recognized that 0b11100011 is a binary number and converted it to the equivalent unsigned base 10 equivalent of 227 and the base 10 signed equivalent of -29. It also displays the hexadecimal equivalent.

$ ncc 0xE3
0xE3 (base 16)  1110 0011 (base 2)  0b11100011 (base 2)  227 (base 10)  -29 (base 10 signed)

In this case ncc recognizes 0xE3 as a hexadecimal number and converts it to binary, decimal, and signed decimal.

Some requirements and notes:
  • Your version of ncc must implement the conversion algorithms described in Section 1.4 of DDCA. That is you cannot use existing library functions or variations of printf() to convert from one number system to another.
  • The argument given to ncc will be a string (available in argv[1]).
  • If no argument is given print an error message, then a usage message and exit.
  • If an invalid number is provided, output and error message, then a usage message and exit.
  • You can assume a maximum value of 32 bits and you should do error checking to ensure value that exceed 32 bits are rejected.
  • You need to get git working directly on your RPi.
  • Must show how you can compile and run your solution on your RPi (no credit if you cannot do this)
    • If for some reason you have hardware problems with your RPi at the last minute you can ensure success by having your code in Github. You can clone your code to my RPi for demonstration purposes.
Extra Credit (Each worth one point)
  • Submit 24 hours early and demo on Tuesday September 13th.
  • Support for up to 64 bit numbers (on your 32 bit RPi). You need to come up with a demonstration that this works for all number types.
  • If no arguments are given, read a number one at time from standard input (stdin) and convert each number appropriately.
    • E.g., $ ncc < nums.txt





Comments