CSci223 - Spring 2005
Programming Assignment #2
Implementing Bit-Level Functions
For your second programming assignment you will be implementing four bit-level functions. This assignment is somewhat artificial, as these functions are generally implemented in hardware. However, this assignment should help you understand how to manipulate data at the bit-level. You will be implementing is_negative(), equal(), is_greater_than(), and multiply(). Their prototypes are included in the supplied prog2.h file.
For all functions you may assume that an integer is 32 bits in size. The functions is_negative() and equal() must return the correct answer for all negative and nonnegative integers. However, is_greater_than() and multiply() need only return correct answers for nonnegative numbers.
You should begin this assignment with the code in this tarball. The only file that must be modified is the prog2.c file. Take care to ensure that your prog2.c works with the "standard" Makefile and prog2.h files. A test.c file is provided, but is empty. You should put code to test your functions in this file. The only file you should submit is the prog2.c file.
The is_negative() function should return true (1) if its argument is negative and false (0) otherwise. This should accomplished without the use of any comparison operators.
The equal() function should return true if its argument are the same number and false otherwise. The numbers should be examined bit by bit to determine if they are the same. Comparison operators may be used, but not to directly compare the two numbers.
The is_greater_than() function should return true if the first argument is greater than the second argument and false otherwise. Once again, this should be accomplished by examining the numbers bit by bit. Comparison operators may be used, but not to directly compare the two numbers.
The multiply() function should return the correct answer for any two nonnegative numbers. This should be accomplished using left shift and addition. The multiplication operator cannot be used.
This assignment will be graded according to the Programming Assignment #2 Grading Sheet. Any solutions that don't compile on onyx using the supplied Makefile will receive a healthy deduction.
Students should submit their solutions by email to the instructor. They should only submit the prog2.c file.
This assignment is due by class time on Monday, February 21st. It will be considered late at 11:00am on Tuesday, February 22nd. Any solutions received after graded solutions have been distributed to the class will receive a zero. Graded solutions will be distributed in class on either February 23rd or 25th.
Please review the Honor Code section of the syllabus and be sure you are familiar with the applicable documents.