ECE-C490 Security in Computing / Winter Term 2005
Quiz #1 Solutions

Consider floating-point addition as a computer would perform it. Add the following two numbers by following the steps below.

A: 0.112 x 103

B: - 0.840 x 102

1)Convert these numbers to the IEEE standard for floating-point numbers, with 1 sign bit, an 8-bit signed exponent in excess-127 representation, and a 23-bit mantissa fraction. (Show all of your work!)

We begin by determining the largest power of 2 that is less than or equal to each number. A is equal to 112, so the largest power of 2 less than or equal to 112 is 64, or 26. Thus the exponent will be 6 (but remember, we are working in excess-127 format, so this will be represented as 10000101). To determine the mantissa, we divide 112 by 64 and obtain 1.75 – we are only concerned about the fractional portion of the result (the 1 is assumed present in IEEE format) so we convert 0.75 to binary and obtain 0.1100…, which becomes our mantissa.

We obtain the representation of 84 similarly. Again, the largest power of 2 less than or equal to 84 is 64, so the exponent for B will be equal to the exponent of A. 84/64 gives us 1.3125, and converting 0.3125 to binary gives us 0.010100… This will be our mantissa.

A is positive, so its sign bit will be 0. B’s will be 1.

A: / 0 / 10000101 / 1100…0
B: / 1 / 10000101 / 010100…0

2)Perform the addition using the rules for floating point arithmetic. Be sure to normalize the result if necessary, and write your final answer in the box below:

Following the steps for floating point addition:

  • The exponents of the two numbers are equal, so we do not need to shift either mantissa.
  • We set the exponent of the result equal to the larger exponent (again, they are equal, so the resulting exponent will be set to 10000101).
  • We perform addition on the mantissas. In this case, we are in fact subtracting .0101 from .1100. This leaves us with .0111. But remember – in IEEE format, we always assume that the mantissa is of the format 1.xxxx, where xxxx is the fractional form displayed. In other words, the leading ‘1’ is assumed. Therefore, we must normalize the result to ensure that there is in fact a leading 1. In order to do so, we take the result:

0.0111

and shift it to the left two bits to obtain a result with a leading 1:

1.1100…

But each time we shift, we must reduce the exponent of the result by 1 to compensate. Thus we reduce the value of the exponent twice and obtain a final result of:

0 / 10000011 / 1100…0

You can check that this result is correct by doing the following:

The value of the exponent as-is = 131. Remember, however, that it is in excess-127 format, so we subtract 131-127 to obtain 4. Therefore, we multiply the mantissa by 24.

The mantissa has an assumed leading 1, and a fractional value equal to .11 – in decimal, .75. Therefore we multiply 1.75 by 24 and obtain 28, which is the correct result (remember, we were adding 112 and –84).