CS202 - Assignment Four
Due: 2018-10-16 9:00a
Solution to problems
Solution to code
Objectives
- More practice with numbers systems and C
- Get really acquainted with floating point numbers
Problems
[15 points] Martin, problem 22
[9 points] Martin, problem 24
[12 points] Martin, problem 25
[20 points] Floating point
Martin describes an 8-bit floating point representation. I would like you to write a program that prints out all 256 different values that this representation can represent. Martin discusses both excess-4 and excess-3 for the representation of the exponent. Please use excess-3.
I strongly recommend starting by writing a function that takes an integer, uses bit manipulation to read the first byte out in Martin's format (i.e., separates out the sign, exponent, and mantissa), and converts it into a floating point representation.
Note that Martin essentially follows the IEEE standard with respect to special values. If the exponent is 000, then the number is denormalized (i.e., no ghost 1, and the exponent is bias-1). If the exponent is 111, then the number is +/- infinity if the mantissa is 0, and NaN if it is not.
For the output, I would like a two digit hexadecimal representation of the number being converted and the converted value. Keep the output of your program to this exact format (we will be diffing your output against mine). Here is what the start of the output looks like:
> ./float
00: 0.000000
01: 0.015625
02: 0.031250
03: 0.046875
04: 0.062500
05: 0.078125
06: 0.093750
07: 0.109375
08: 0.125000
09: 0.140625
0a: 0.156250
0b: 0.171875
0c: 0.187500
0d: 0.203125
0e: 0.218750
0f: 0.234375
10: 0.250000
11: 0.265625
12: 0.281250
13: 0.296875
14: 0.312500
...
Put this in a file called hw4.c
[5 points] Follow the submission directions
- If the first section is turned on paper, it must be legible and have your name and section on the top
- If the first section is turned in online, it must be a PDF or RTF file (no .doc or .docx files)
- Each file must be named according to the instructions above.
- Make sure that the assignment runs on Linux before you submit it. Do not assume that it will -- check it.
- Each function should be commented to describe its function
- At the very top of each file, you will place a block comment that follows this format exactly:
/*
Assignment 4
Name:
Email:
Date:
Collaborators:
To compile:
To run:
*/
The name
, date
, and email
fields should be self explanatory. In the collaborators
field, you should list everyone who helped you with this assignment including classmates, tutors, and myself. In the to compile
and to run
fields, provide the commands required to compile and execute your code (i.e., someone should be able to copy these commands directly onto a command line and run your code). The to run
should include usage instructions (what arguments need to be provided and what they do).
Turning in your work
Submit the completed assignment on Canvas.