CS611
Fall 2002
Programming Assignment 1
Due Sunday September 15


The IAS computer supports 40-bit 2's complement values. The machine is connected (conceptually) to an input card reader and an output card punch. A card punch, whether human driven or computer driven, has only 16 keys, labeled with 0-9 and a-f. Each key produces a 4-bit output, which is equivalent to the standard hexadecimal encoding of the key's label. A card contains 12 40-bit words, represented with 120 4-bit symbols. Each symbol is printed at the top of the card with its corresponding bit pattern represented via holes punched in the column below the symbol.

This arrangement allows the machine to output numbers in a primitive, human-readable, decimal notation. A 40-bit binary value requires up to 12 decimal digits plus a sign indicator. An individual decimal digit can be represented with its corresponding hexadecimal value and the sign can (inelegantly and arbitrarily) be represented by 'a' standing for '+' and 'b' standing for '-'. In this manner, therefore, up to 13 4-bit symbols (52 bits) are required to represent a 40-bit binary value.

So, for example, the 40-bit value 0000000100 (displayed in hexadecimal) could be converted to decimal and then punched on a card using 13 columns as a000000000256. And ffffffffff could be punched as b000000000001.

Likewise, this scheme could be used to input data. A human could punch a card using the decimal notation. The computer could then read the card, convert the decimal value to binary, and then compute with the value.

Your assignment is to write two routines using C:

  1. btod: convert a 40-bit binary value to a 52-bit binary-decimal value.
  2. dtob: convert a 52-bit binary-decimal value to a 40-bit binary value.

Both routine takes two void* arguments. The first argument points to the input value and the second argument points to the location where the output value should be placed. The values are assumed to be in Little Endian format and an argument value points to the first (low address) byte of the five bytes than contain a 40-bit value or of the seven bytes that contain a 52-bit value. Note: there are 7 bytes and therefore actually 56 bits in the buffer for a binary-decimal value. In this case the upper four bits are always set to 0.

The btod routine returns void. You do not need to error check the arguments.

The dtob routine returns an integer value indicating success (1) or failure (0) of the conversion. The conversion might fail because there is an illegal character in the input or because the converted value overflows 40-bits. If the conversion fails, the output buffer can contain garbage (e.g. a partial conversion) upon return.

Grading will be based upon completed, correct functionality:

Place the btod routine (and its supporting code) in the file btod.c. Place the dtob routine (and its supporting code) in the file dtob.c.

Stubs for these two files, two main routines for testing, a Makefile for building the test programs, and two simple test input files are provided in turing.unh.edu:~cs611/public/prog1.

Your job is to complete the stub files and then develop additional tests to be sure that your code is correct.

Your program will be graded primarily by testing it for correct functionality. However, you may lose points if your program is not properly structured or adequately documented. See the mandatory guidelines given in the course overview webpage.

You must write your programs in C.

Your assignment should be submitted for grading from a CIS Linux machine (e.g. turing.unh.edu). To turn in this assignment, type:
~cs611/bin/submit prog1 btod.c dtob.c

Do not turn in any other files!

Submissions can be checked from a CIS Linux machine by typing:
~cs611/bin/scheck prog1

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday September 16. Late submissions will be accepted at the penalty of 5 points per day up to one week late.

Your programs will be graded using a CIS Linux machine (e.g. turing.unh.edu) so be sure to test in that environment.

Remember: as always you are expected to do your own work on this assignment. Copying code from another student or from sites on the internet is explicitly forbidden!

If you developed your code on a DOS/Windows system, be sure to appropriately transfer your files to a CIS Linux system before submitting them. You need to convert the DOS ASCII file format to UNIX format. If you need help with this, please see me.


Last modified on August 29, 2002.

Comments and questions should be directed to hatcher@unh.edu