CS 241 Data Organization using C
Lab 3: Playing with bases
September 5, 2018
The purpose of lab today is to get you familiar with more code and to solidify
your understanding of concepts done in lecture by hand, like our greedy subtraction
algorithm to turn base 10 numbers into binary numbers.
1 Getting Started
Download the binary.c file off the course webpage under the lab subdirectory.
(Remember the linux command to do this from the last labs?)
To compile the code, use the following command.
gcc -ansi -pedantic -Wall binary.c
2 Adding to the code
- First, create a function to read in a base-10 number from standard in. This
function should return an int. You should largely be taking code from last
lab and slightly modifying it.
- Next, write a function that takes in a positive base-10 integer and prints out
the corresponding (unsigned) binary string. This function needs to use the
greedy subtraction algorithm we used in class. All binary strings should be
length 16.
- To test this function, include some testing code in your main method.
Create two files testbinary.in and testbinary.out. These files will
need to have an interesting number of correct testing cases in order
to get credit for having completed this step. Use the function created
in the first step to read in numbers from this file, and then print out
the binary string.
- Edit the function from above to print out an error message if passed an integer
that is larger than your binary string (unsigned) can handle.
- Include some test casees for this step in your text files. This step will
only be considered to be complete with corresponding test cases.
3 More time?
4 Turning in your program
It’s ok not to finish this assignment – get through as many test cases as you
can.
Zip up your binary.c file along with your test cases into a zip file entitled
yourCSUsername.zip. Then drop the zip file into the lab-03 folder in the dropbox.