CS 270 Programming Assignment #1
Due Tuesday September 9th (by 11:59pm)
Introduction:
Programming assignments and the associated homework questions are
to be done individually. The homework questions listed in this
assignment description should be answered in the README file.
For this assignment you will be a number detective. The goal is to learn
how numbers are represented in the machine(s) you are using.
The Assignment
Implement the following functions, each in a separate file named based on the function (e.g. printHexForInt.c).
void printHexForInt( int x )
Print hex for a given integer to standard out
void printHexForFloat( float x )
Print hex for a given float to standard out. Hint 1: %x only works for
integer types. Hint 2: see printBinForFloat implementation that will be
given in recitation.
void printBinForInt( int x )
Prints an integer to a string of bits. Group the bits into sets of size
four. It is ok to assume that integers are represented with 32-bits, but
that assumption should be tested with an assert.
void printBinForFloat( float x )
Print a float to a string of bits broken into sign, exponent, and fraction.
The prototypes for all of the functions should be in a pa1.h file, similar to the pa0.h file you were given for PA0.
Write a unit test for each function. Within each unit test, test that the function returns the same result as you calculate by hand for the conversions in the Homework Questions (see below). Since the functions in this assignment all print to standard out, you will need to visually inspect that the results are as expected. Each unit test should contain at least four different test cases written by you including the relevant examples in the below homework questions. Read the chapter on number representation to find some examples.
When you are finished your PA1 subdirectory will contain the following files:
Makefile
cs270.doxygen.config
pa1.guideline
pa1.h
printBinForInt.c
test_printBinForInt.c
printHexForFloat.c
test_printHexForFloat.c
printHexForInt.c
test_printHexForInt.c
printBinForFloat.c
test_printBinForFloat.c
Keep reading this writeup for instructions on how to get started.
README and Homework Questions
For this assignment the README file should contain
your name, userid, and answers to the the following questions.
Copy the question into the file and then type in the answer directly after the copied question.
If you answer the first four questions with respect to two or more machines, then make
sure to indicate which answer corresponds to which machine.
- Are you doing your assignments on the school machines or at home? If at school what is the name of the machine you are using to answer these questions?
- Type gcc --version on the command line. What is the output?
- Does the machine you are on use the little endian or big endian representation? How did you determine that?
- Is the machine you are using 64 bit or 32 bit? How did you determine that?
- What are the ASCII codes for the characters in your family name?
- Show the representation of -305 (base 10) in the following representation schemes (assume 16-bit words):
(a) sign magnitude,
(b) one's complement, and
(c) two's complement
- Show the representation of 284 (base 10) in the following representation schemes (assume 16-bit words):
(a) two's complement and (b) hexadecimal.
- Show the representation of 101.5 (base 10) in the following representation schemes (assume 32-bit words):
(a) binary float and (b) hexadecimal float.
- What is the range of base 10 integers that can be represented with 8 bits for each of the following representations? (a) sign magnitude, (b) one's complement, and (c) two's complement
Getting Started
The start of a Makefile, a doxygen configuration file (optional, try command make docs and open html/index.html), and the start of one of the assigned functions and its unit test have been provided in the public directory (~cs270/public/PA1-start/). Let a copy of the PA1-start subdirectory become your initial PA1 subdirectory.
To accomplish this do the following at the command prompt:
% cd ~
(Just to make sure you are in your home directory.)
% cp -r ~cs270/public/PA1-start ~/CS270/PA1
Now set up a subversion repository for PA1.
See SVN Notes for directions for setting
up a subversion repository and working directory.
Look carefully at the provided files. Type make inside of your
PA1/ working directory to see the following output:
Compiling each C source file separately ...
gcc -c -g -std=c99 -Wall -O0 printHexForInt.c
Compiling unit test test_printHexForInt
gcc -g -std=c99 -Wall -O0 test_printHexForInt.c printHexForInt.o -o test_printHexForInt
Executing unit test test_printHexForInt
./test_printHexForInt
===== Testing printHexForInt =====
42 in hex should be
0x2A
output from printHexForInt =
IMPLEMENT ME!
-42 (as a 32-bit integer) in hex should be
0xFFFFFFD6
output from printHexForInt =
IMPLEMENT ME!
Done with unit test test_printHexForInt
You will have to add file names to the C_SRCS, C_OBJS, and TESTS lists in the Makefile as you implement more functions and their corresponding unit tests.
Submitting your Assignment
-
Make sure there are unit tests for all of the functions in the assignment.
-
Make sure your code follows the code style requirements (see http://www.cs.colostate.edu/~cs270/Programs/code-requirements.html).
-
Put all of the required information and answer the associated homework questions in the README file.
- The subversion.txt file should include output from the following commands:
% svn log -r HEAD:1 // must be done in working directory
% svn info // must be done in working directory
% svnlook tree REPOSITORY_PATH // svnlook must be issued on the machine where the repository is stored
We recommend copying the output of the above commands into an editor and
saving the result as subversion.txt.
-
Do a "make clean" before creating the tar ball for the assignment.
-
Include all the source files, the README file, the Makefile,
and a subversion.txt file in a tar file.
% cd ~/CS270
% tar cvf PA1_username.tar PA1
-
Submit assignment using checkin utility
~cs270/bin/checkin PA1 PA1_username.tar
-
Sanity Check (procedure we will use to grade your assignment):
% mkdir ~/Temp
% cd ~/CS270/
% cp PA1_username.tar ~/Temp
% cd ~/Temp
% tar xf PA1_username.tar
% cd PA1
% make all // this should compile and run unit tests
We will also be copying in our own unit tests for each function, and
we will be reading through the code comments for the code style requirements
portion of the grade.
Late Policy
Late assignments will be accepted up to 24 hours past the due date and time for a deduction of
20% and will not accepted past this period. One minute late is still late.
mstrout@cs.colostate.edu
.... September 9, 2008