Andrew login ID:
CS 15-213, Fall 2006
Wednesday October 4, 2006
Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID
on the front.
Write your answers in the space provided below the problem. If you make a mess, clearly indicate
your final answer.
The exam has a maximum score of 56 points.
The problems are of varying difficulty. The point value of each problem is indicated. Pile up the easy
points quickly and then come back to the harder problems.
This exam is OPEN BOOK. You may use any books or notes you like. Calculators are allowed, but
no other electronic devices. Good luck!
Page 1 of 10
Problem 1. (8 points):
Assume we are running code on an IA32 machine, which has a 32-bit word size and uses two’s complement
arithmetic for signed integers. Consider the following definitions:
int x = foo();
unsigned ux = x;
Fill in the empty boxes in the table below. For each of the C expressions in the first column, either:
State that it is true of all argument values, or
Give an example where it is not true.
True / Counterexample
x < 0
2) < 0
x > 0
(x+1) > 0
x > 0
(˜x + 2) <= 0
(x>>31) == -1
x < 0U
x < 0
((x ˆ x>>31) + 1) > 0
((x>>31)+1) == (x>=0)
x >= 0
((int)(ux >> 31) + ˜0) == -1
-(x | (˜x + 1)) > 0
Page 2 of 10
Problem 2. (8 points):
Consider the following 5-bit floating point representations based on the IEEE floating point format. This
format does not have a sign bit – it can only represent nonnegative numbers.
exponent bits. The exponent bias is 3.
Numeric values are encoded as a value of the form
is exponent after biasing, and
is the significand value. The fraction bits encode the significand value
using either a denormalized
(exponent field 0) or a normalized representation (exponent field nonzero).
Below, you are given some decimal values, and your task it to encode them in floating point format. If
This is the end of the preview. Sign up
access the rest of the document.