Fall 2013
Lab 3
Due Wednesday, September 11

Dissecting Floating points and Two's Complement Integers

Begin this lab by downloading the following files:
  1. makefile: a Makefile
  2. dissect_main.c: Main file for the program
  3. convert.h: A header file with 2 structs and 2 functions for you to implement in a file called convert.c

Detailed instructions

  1. Log on to one of the computers in the lab.
  2. Open up a terminal
  3. Make a directory entitled lab3
    mkdir lab3
  4. Change to the lab3 directory
    cd lab3
  5. In the lab3 folder, download the 3 files for this lab. You are free to use any editor you can find on agate that you are happy with. Many students have been using SciTE, so if you have no preference for editor, that is a good place to start. You will need to create the dissect.c file, that is where all of your code for this lab is going to go.
  6. To compile your file, in the lab3 directory type:
    Remember that you have to make the dissect.c file, and put stub functions in it, even if the stub functions do nothing, to get this program to compile.
  7. When you are done, submit your source file. In order to submit your file, you will need to be SSH'd in to agate.
    ~cs520/bin/DoSubmission.py lab3 dissect.c
    I will use my own copy of the main function, the makefile, and the header file, so if you do modify those, your modifications will not be used when grading your program. I may also be using your function with different main functions.


Please submit whatever you have at the end of lab, even if it is incomplete. You have the rest of today to finish this assignment.


Your program will be graded primarily by testing it for correct functionality.
  1. 10 points will be awarded for correctly filling in the sign part of the long's struct
  2. 5 points will be awarded for correctly filling in the value part of the long's struct for positive numbers
  3. 15 points will be awarded for correctly filling in the value part of the long's struct for negative numbers
  4. 5 points will be awarded for correctly filling in the sign part of the double's struct
  5. 15 points will be awarded for correctly filling in the exponent part of the double's struct
  6. 40 points will be awarded for correctly filling in the mantissa part of the double's struct
  7. 10 points will be awarded for calling assert(false) if your function is called with NaN, negative infinity, or infinity. In order to get full credit for this, you have to explicitly have a call to assert(false) written like that.

In addition, remember, you may lose points if your program is not properly structured or adequately documented. Coding guidelines are given on the course overview webpage.


Once you download the 3 files, the first step is to make a c file that implements the missing functions. I would recommend starting by writing a .c file that has the functions, but just put 0 in all of the structs's fields.

What is a struct?

The short answer is that a struct is a data type that contains other data types. These can be either primitive types, as is the case with our struct, or other structs. Structs are very similar to classes, except structs generally don't have member functions the way classes do, they only have data members. As a historical note, in the ancient days before C++, people used to use structs and function pointers (which we will cover later) to get something very similar to object oriented programming in C. If you would like a brief tutorial on structs, this is by Brian Kernighan, a very well respected computer scientist who ever CS major should know of. Wikipedia him one day when you're bored if you don't recognize his name. Structs are most commonly used in c to implement data structures. For example, if you were making a linked list, a the nodes in the linked list could be a struct.

Next Steps

I anticipate this being a fairly straightforward lab, and it wouldn't surprise me if some students finished extremely early. If that is indeed the case, you can go if you have other things to do, but I would strongly recommend you take this opportunity to start doing the homework, while I am around and can answer questions. Many students indicated that they felt rushed on the previous assignment, and getting started early will help fix that problem.
Last modified: Tue Sep 10 04:27:33 EDT 2013