CS 61C (Fall 2007)
Homework Assignment 6One exercise, submit as "hw6". Due 2:45pm before lecture 10/10/2007.
This homework is intended to provide you with practice working with floating-point representations.
Submit your solution by creating a directory named hw6 that contains a file copied from template.txt. From within that directory, type submit hw6. Note that we will be autograding this assignment (except for explanations of course) in the stye of the quizzes, and you should format your template.txt accordingly.
This is not a partnership assignment. Hand in your own work.
Consider two representations for six-bit positive floating-point values. One—we'll call it representation B (for binary)—is a radix-2 representation. It stores an exponent in two bits, represented in two's complement (not biased). It stores the normalized significand in four bits, using the hidden bit as in the IEEE floating-point representation, making 0 unrepresentable. Thus the value 2.5 (decimal) = 10.1 (binary) would be represented as
01 (1) 0100
and the value 7/8 (decimal) = 0.111 (binary) would be represented as
11 (1) 1100
The second representation—we'll call it representation Q (for quaternary)—is a radix-4 representation. Like representation B, it stores an exponent—but of 4, not 2—in two bits, represented in two's complement. It stores the significand in four bits, which is the same as having two base-4 digits, with the first base-4 digit being to the left of the quaternary point and the second base-4 digit being to the right of the quaternary point. There is no hidden bit. The significand is not necessarily normalized. 2.5 (decimal) thus is represented as
since 2.5 (decimal) = 2.2 (quaternary) = 40 × (2 × 40 + 2 × 4-1).
7/8 (decimal) = 3 × 4-1 + 2 × 4-2 = 4-1 × (3 × 40 + 2 × 4-1), so it's represented as
The decimal fraction 3/4, which in quaternary is 0.3, has two representations, since it's expressible either as 40 × 3/4 or 4-1 × 3:
11 1100 00 0011
Find a value representable in representation B and not in representation Q. Defend your answer.
Please put your answer in representation B in template.txt.
Fill out the following table.
|maximum representable value (in decimal)||minimum positive representable value (in decimal)||number of distinct representable values other than 0|
|representation B||Your answer here||Your answer here||Your answer here|
|representation Q||Your answer here||Your answer here||Your answer here|
Put all of your answers in decimal in template.txt.
Please note that because there is no sign bit in either representation B or representation Q, we are using the mathematical convention that 0 is neither negative nor positive. In IEEE 754 the sign bit means that we have no way of representing mathematical 0, and must settle for ±0.