Step 0. Introduction
In this lab you will write a number converter, implement memdump to display memory content, introduction to pointers, implement string functions with pointers, and bit operations.
Step 1. Writing a number converter
Using convert.c write a program to convert a given number from one base to another. The format is:1
convert <basefrom> <baseto> <number>
You now know how to access the arguments on the command line. Assume that basefrom and baseto are integers between 2 and 25 (both inclusive). Since base 16 uses the characters A, B, C, D, E, F to represent decimal numbers 10 through 15, bases 17 through 20 will involve additional characters. For example, base 20 will involve the additional characters G, H, I and J. Use defensive programming to make sure your command line arguments are what you would expect. You may assume that no number (in any base) has more than 32 digits, and all numbers are nonnegative.
To convert a number, say (123)9, from base 9 to another base such as base 8, simply convert from base 9 to decimal (i.e., base 10), to get the number, i.e.,
(1 x 92) + (2 x 91) + (3 x 90) = (102) 10
and then convert to base 8 by doing repeated division, just the way you convert from decimal to binary (base 2) - simple, because you understand decimal (base 10) arithmetic. In this case you should get (146)8. The following link may refresh your memory.
Step 2. Implement bit operations.
You will implement the bit operations described in the file lab4-src/bits.c . To test your implementation run testall.
Notice that the printbits() should prints the 1s and 0s in one line followed by another line with the indices (mod 10) of the bits.
Step 3. Our Tests
Also, make sure that your program passes our tests. To run the tests, compile your program and type1
./testall
or run each individual test as indicated in the output.
Make sure that all tests pass and testall gives the maximum points.
Step 4. Turning In your Project
Follow these instructions to turn in lab4.1
2cd cs240
turnin -c cs240 -v -p lab4 lab4-src