IEEE 754 floating-point exercises — laps, gaps to the record and an old 16-bit stopwatch (and the 3.25 that turned into 2.0000012)

Revising for the midterm with a classmate, we set each other challenges: one said a number and the other converted it to IEEE 754 as fast as possible. I got 3.25. Binary 11.01, normalised 1.101 · 2¹, exponent 128 = 10000000, mantissa 101. I wrote the 32 bits, turned them into hexadecimal (40000005) and, proudly, typed them into a converter to check: 2.0000012. I had put the three mantissa bits pushed to the right, as if it were an integer, instead of right after the point. One placement mistake and 3.25 became almost 2.

These exercises are designed so that those mistakes happen to you here and not in the exam. There are three levels, from the most direct one to the club’s old stopwatch with a format that is not the standard one, a «What’s wrong here?» section with other people’s solutions hiding a mistake, the step-by-step solutions, a practice quiz and the cheat sheet. If you get stuck, the guided practice solves problems just like these with every step and the theory explains it from scratch.

How to use this article

  1. Do each level on paper before opening its solution, as in the exam: binary, normalise, fields and hexadecimal, written down.
  2. Compare with the expected result under each statement. If it does not match, look for the mistake before reading the solution.
  3. In «What’s wrong here?», predict what is wrong before reading the explanation.
  4. Finish with the quiz, which marks itself and does not count for anything: repeat it until you get it all right.

Level 1: the basics

Statement. The race stopwatch stores in IEEE 754 single precision:

a) A runner’s warm-up lap: 12.5 s. Give it in hexadecimal.

b) The reaction time at the start: 0.75 s. Give it in hexadecimal.

c) One of the stored readings is C0300000. What number is it?

Expected result: a) 41480000; b) 3F400000; c) −2.75.

In b) the number is less than 1: the real exponent is negative. In c), the leading C already tells you the sign: 1100, it starts with 1.

Level 2: negatives, small numbers and precision

Statement.

a) A runner has improved their time by 27.5625 s and the stopwatch stores the gap as −27.5625. Give it in hexadecimal.

b) What number is the reading 3E200000?

c) The stopwatch is about to store 0.2 s and 0.625 s. Is either of them stored exactly? Give the hexadecimal of each.

d) How many single-precision numbers are there strictly between 8 and 9 (counting neither 8 nor 9)?

Expected result: a) C1DC8000; b) 0.15625; c) 0.2 is not exact (3E4CCCCD), 0.625 is (3F200000); d) 220−1=1,048,5752^{20} – 1 = 1{,}048{,}575.

In c), do the table of multiplications by 2 and see whether it reaches 0. In d), think about which exponent the numbers between 8 and 9 have and how many mantissa bits are left for the fractional part.

Level 3 (challenge): the club’s old stopwatch

The club has an old stopwatch that stores times in 16 bits with its own format, which is not IEEE 754:

  • 1 sign bit (0 positive, 1 negative), on the left.
  • 5 exponent bits in excess 16 (25−12^{5-1}), with no reserved values.
  • 10 bits of fractional mantissa, normalised: the point goes to the left of the first 1, 0.1…0.1\ldots

Statement.

a) Work out the largest positive number and the smallest positive number it can store, without a hidden bit and with a hidden bit (in that case, the 1 of 0.1…0.1\ldots is not stored).

b) Represent the 83.375 s lap without and with a hidden bit, in hexadecimal.

c) Represent the −0.15625 s gap in both ways.

Expected result: a) largest: 32736 without a hidden bit and 32752 with one; smallest positive: 2−172^{-17} in both cases; b) 5E9B and 5D36; c) BA80 and B900.

With 5 bits in excess 16 the exponents go from −16 (00000) to +15 (11111). The largest mantissa without a hidden bit is 0.1111111111; with a hidden bit eleven ones fit after the point, because the first one is not stored.

What’s wrong here?

Three classmates have handed in their solutions. All three have a mistake. Before reading the explanation, try to find it.

Fragment 1: 21.25

21.25 = 10101.01 = 1.010101 · 2^4
sign 0 · exponent 4 = 00000100 · mantissa 010101
0 | 00000100 | 01010100000000000000000 = 022A0000

Can you see it? The exponent has been stored as plain 4. The excess is missing: 4+127=131=100000114 + 127 = 131 = 10000011. With 00000100 the real exponent would be 4−127=−1234 – 127 = -123, and 022A0000 is about 1.25⋅10−371.25 \cdot 10^{-37}: a 21-second lap turned into almost nothing.

Thinking «the exponent is 4» and storing it as it is. The exponent field never stores the real exponent: it stores the real one + 127.

The right solution: 0 | 10000011 | 010101000… = 41AA0000.

A «normal» exam number (between 1 and a few thousand) always starts with 3, 4, B or C in hexadecimal. A 0 or an 8 in front of a number like that is a sign of an exponent without the excess.

Fragment 2: 10.625

10.625 = 1010.101 = 1.010101 · 2^3
sign 0 · exponent 3 + 127 = 130 = 10000010 · mantissa 1010101
0 | 10000010 | 10101010000000000000000 = 41550000

Here the exponent is fine, but the hidden 1 has slipped into the mantissa: 1010101 instead of 010101. With the formula, 41550000 reads as 1.1010101⋅23=1101.0101=13.31251.1010101 \cdot 2^3 = 1101.0101 = 13.3125, not 10.625.

Copying every digit of the normalised form into the mantissa. The 1 before the point is never stored in IEEE 754.

The right solution: 0 | 10000010 | 0101010000… = 412A0000.

Fragment 3: 3.25

3.25 = 11.01 = 1.101 · 2^1
sign 0 · exponent 1 + 127 = 128 = 10000000 · mantissa 101
0 | 10000000 | 00000000000000000000101 = 40000005

This is my midterm mistake. The mantissa 101 has been padded with zeros on the left, as if it were a 23-bit integer. But the mantissa is the digits after the point, in order: 1.101 is 1.10100000…, so the zeros go after it.

Fragment 3: which side do the zeros go?3.25 is 1.101 times 2 to the 1. Wrong: the mantissa 101 in the last three bits gives 40000005, about 2.0000012. Right: 101 in the first three bits of the mantissa gives 40500000, 3.25.wrong: the mantissa pushed to the right0100000000000000000000000000010140000005= 40000005 = 2.0000011920…right: the mantissa starts just after the point0100000001010000000000000000000040500000= 40500000 = 3.25
The mantissa is the digits after the point: the padding zeros go on the right.

Aligning the mantissa to the right. The padding zeros go on the right, as in 0.5 = 0.500.

Look at the last hexadecimal digits: in an «exam» number, with few mantissa bits, the last digits are 0. A 5 at the end of such a simple number is suspicious.

The right solution: 0 | 10000000 | 1010000… = 40500000.

Solutions

Level 1

a) 12.5. 12=1100212 = 1100_2 and 0.5=0.120.5 = 0.1_2, so 12.5=1100.12=1.1001⋅2312.5 = 1100.1_2 = 1.1001 \cdot 2^{3} (the point jumps 3 places left). Sign 0; exponent 3+127=130=100000103 + 127 = 130 = 10000010; mantissa 1001 and zeros.

0 | 10000010 | 10010000000000000000000
0100 0001 0100 1000 0000 0000 0000 0000  =  41480000

Why split the number in two: the integer part is converted by dividing by 2 and the fractional part by multiplying by 2. Then you join 1100 and .1 and all that is left is moving the point.

The step people skip most is the last one: the groups of 4 for the hexadecimal are made over the 32 bits in a row, without looking at where each field ends.

GroupBitsWhat it holdsHex
1st0100sign 0 and exponent 1004
2nd0001exponent 00011
3rd0100exponent 0 and mantissa 1004
4th1000mantissa 1 and three zeros8
5th to 8th0000padding zeros0

Converting each field to hexadecimal separately (the exponent 10000010 as 82) and writing the pieces one after another. You don’t get 41480000: the sign takes 1 bit and the exponent 8, not whole hexadecimal digits.

b) 0.75. 0.75=0.5+0.25=0.112=1.1⋅2−10.75 = 0.5 + 0.25 = 0.11_2 = 1.1 \cdot 2^{-1} (one jump to the right). Sign 0; exponent −1+127=126=01111110-1 + 127 = 126 = 01111110; mantissa 1 and zeros.

0 | 01111110 | 10000000000000000000000
0011 1111 0100 0000 0000 0000 0000 0000  =  3F400000

Look at the first digit: 3, because the stored exponent starts with 0 (number less than 1).

There is no need for the multiply-by-2 table here: 0.75 is 0.5 + 0.25, two powers of 2 you can spot by eye. What you have to think about before the arithmetic is which way the point goes: the first 1 is to its right, the point moves right and the exponent comes out negative. A number less than 1 always stores an exponent below 127.

Writing exponent +1 because «the point has moved one place». You store 128 and get 40400000, which is 3: four times 0.75.

c) C0300000. In binary, 1100 0000 0011 0000…:

  • Sign 1: negative.
  • Exponent 10000000 = 128 → 128−127=1128 – 127 = 1.
  • Mantissa 011 → 1.011.
  • Value: −1.011⋅21=−10.112=−(2+0.5+0.25)=−2.75-1.011 \cdot 2^{1} = -10.11_2 = -(2 + 0.5 + 0.25) = -2.75.

Reading goes the opposite way to writing: first the bits, then you cut them into fields. The first three digits are enough, because the rest are zeros: C, 0 and 3 are 1100 0000 0011, and the cut falls like this: 1 | 10000000 | 011.

Forgetting the hidden 1 when reading. With 0.011 instead of 1.011, exponent 1 gives 0.11 in binary, which is 0.75, and you get −0.75 instead of −2.75.

Level 2

a) −27.5625. 27=16+8+2+1=11011227 = 16 + 8 + 2 + 1 = 11011_2; 0.5625=0.5+0.0625=0.100120.5625 = 0.5 + 0.0625 = 0.1001_2. So 27.5625=11011.1001=1.10111001⋅2427.5625 = 11011.1001 = 1.10111001 \cdot 2^{4}. Sign 1; exponent 4+127=131=100000114 + 127 = 131 = 10000011; mantissa 10111001.

1 | 10000011 | 10111001000000000000000
1100 0001 1101 1100 1000 0000 0000 0000  =  C1DC8000

The sign changes nothing else: you work out 27.5625 as if it were positive and put a 1 in front at the end. That is why C1DC8000 and the positive one, 41DC8000, only differ in the first digit (C = 1100, 4 = 0100).

Taking the two’s complement of 41DC8000, as with integers. You get BE238000, which the stopwatch would read as roughly −0.1597. In IEEE 754 the sign is a separate bit; there is no complement.

b) 3E200000. 0011 1110 0010 0000…: sign 0; exponent 01111100 = 124 → −3; mantissa 01 → 1.01. Value: 1.01⋅2−3=0.001012=0.125+0.03125=0.156251.01 \cdot 2^{-3} = 0.00101_2 = 0.125 + 0.03125 = 0.15625. It is the gap to the record from the theory, now positive: only the first digit changes, from B to 3.

The stored exponent, 124, is below 127: the number is less than 1 before doing any arithmetic. With exponent −3, the point in 1.01 moves three places left and two zeros appear on the way: 1.01 → 0.101 → 0.0101 → 0.00101.

Moving the point to the right with a negative exponent. You get 1010 = 10, which would be 41200000.

c) 0.2 and 0.625. The table for 0.2 gives 0, 0, 1, 1, 0, 0, 1, 1… and 0.2 comes back: it is recurring, 0.2=0.0011‾20.2 = 0.\overline{0011}_2, so it is not exact. Normalised, 1.1001 1001…⋅2−31.1001\,1001\ldots \cdot 2^{-3}: the same mantissa as 0.1 (doubling a number only changes the exponent) and the same rounding up. Exponent −3+127=124-3 + 127 = 124:

0 | 01111100 | 10011001100110011001101  =  3E4CCCCD

The table for 0.2, step by step:

StepCalculationBitLeft
10.2 · 2 = 0.400.4
20.4 · 2 = 0.800.8
30.8 · 2 = 1.610.6
40.6 · 2 = 1.210.2
50.2 comes back—0011 repeats

The final 1 in CCCD is the rounding: the mantissa is cut at 23 bits, which end in …1001100, and the bit that would come next is a 1, so it rounds up: …1001101.

Cutting without rounding and giving 3E4CCCCC. It is 0.19999998…, further from 0.2 than 3E4CCCCD (0.20000000298…).

The table for 0.625 gives 1 (1.25), 0 (0.5), 1 (1.0) and stops: 0.625=0.10120.625 = 0.101_2, exact. Normalised, 1.01⋅2−11.01 \cdot 2^{-1}; exponent 126:

0 | 01111110 | 01000000000000000000000  =  3F200000

The underlying reason: 0.625=0.5+0.1250.625 = 0.5 + 0.125 is a sum of powers of 2; 0.2 is not.

d) Between 8 and 9. Every number in [8,16)[8, 16) has exponent 3: 1.m⋅231.m \cdot 2^3. Between 8 and 9 the integer part is 1000, so the first 3 mantissa bits are fixed at 000 (8 = 1.000 · 2³) and the remaining 20 can be anything: 2202^{20} numbers from 8 (included) to 9 (not included). Taking away 8, 220−1=1,048,5752^{20} – 1 = 1{,}048{,}575 are left. The gap between them is 2−202^{-20}, a bit less than a millionth.

The approach before counting: if all the numbers between 8 and 9 share an exponent, counting them means counting how many mantissas fit with the bits that are left free.

NumberBinaryNormalisedMantissa
810001.000 · 2³000 and twenty zeros
910011.001 · 2³001 and twenty zeros
in between1000.…1.000… · 2³000 and 20 free bits

Counting all the numbers with exponent 3, 223−12^{23} – 1, more than eight million. Those are the ones between 8 and 16.

Level 3

a) Range. The exponents go from 0−16=−160 – 16 = -16 to 31−16=1531 – 16 = 15.

  • Without a hidden bit: the largest mantissa is 0.1111111111=1−2−100.1111111111 = 1 – 2^{-10} and the smallest 0.1000000000=2−10.1000000000 = 2^{-1}. Largest number: (1−2−10)⋅215=32768−32=32736(1 – 2^{-10}) \cdot 2^{15} = 32768 – 32 = 32736. Smallest positive: 2−1⋅2−16=2−172^{-1} \cdot 2^{-16} = 2^{-17}.
  • With a hidden bit: the 1 of 0.1…0.1\ldots is not stored and 10 more bits fit after it: the largest mantissa is 0.11111111111=1−2−110.11111111111 = 1 – 2^{-11}. Largest number: (1−2−11)⋅215=32768−16=32752(1 – 2^{-11}) \cdot 2^{15} = 32768 – 16 = 32752. The smallest positive does not change: 2−172^{-17}.

The hidden bit does not widen the range of exponents: it gains precision (one more mantissa bit), which is why the maximum gets a little closer to 2152^{15}.

The approach: the largest number puts the largest exponent together with the largest mantissa, and the smallest positive one, the smallest exponent with the smallest mantissa. The smallest mantissa is not 0.0000000000: it is normalised and always starts with 0.1.

CaseSignExponentStored mantissaHex
Largest, with or without hidden bit01111111111111117FFF
Smallest positive, without hidden bit00000010000000000200
Smallest positive, with hidden bit00000000000000000000

The same bits are worth different amounts depending on whether you read them with the hidden 1 or without it. That is why the largest changes and the smallest does not: in both cases it is 2−1⋅2−16=2−172^{-1} \cdot 2^{-16} = 2^{-17}.

b) 83.375. 83.375=1010011.011=0.1010011011⋅2783.375 = 1010011.011 = 0.1010011011 \cdot 2^{7}: with a fractional mantissa, the point goes to the left of the first 1, so it jumps 7 places (not 6, as in IEEE 754). Exponent 7+16=23=101117 + 16 = 23 = 10111.

First the number in binary, in parts, as in level 1: 83 = 64 + 16 + 2 + 1 = 1010011 and 0.375 = 0.25 + 0.125 = 0.011. Then the normalisation of this format: the point goes just before the first 1, one place further left than in IEEE 754, and the exponent comes out one higher.

Normalising out of habit as in IEEE 754, 1010011.011=1.010011011⋅261010011.011 = 1.010011011 \cdot 2^6, and storing 6 + 16 = 22. Without a hidden bit you get 5A9B, which this format reads as 41.6875: half the lap.

  • Without a hidden bit, the mantissa is the 10 bits 1010011011 (they fit exactly):
0 | 10111 | 1010011011
0101 1110 1001 1011  =  5E9B
  • With a hidden bit, the first 1 is skipped and the next 10 are stored: 010011011 and a padding 0, 0100110110:
0 | 10111 | 0100110110
0101 1101 0011 0110  =  5D36
Level 3: the lap on the old stopwatch83.375 is 0.1010011011 times 2 to the 7; the exponent in excess 16 is 10111. Without hidden bit the mantissa is 1010011011 and the word 5E9B; with hidden bit the mantissa is 0100110110 and the word 5D36.old stopwatch (16 bits): sign | 5-bit exponent in excess 16 | 10-bit mantissa83.375 = 1010011.011 = 0.1010011011 × 2⁷ → exponent 7 + 16 = 23 = 10111without hidden bit: the 1 of 0.1… is stored01011110100110115E9Bwith hidden bit: that 1 is not stored and one more bit comes in on the right01011101001101105D36largest: (1 − 2⁻¹⁰)·2¹⁵ = 32736 without hidden bit · (1 − 2⁻¹¹)·2¹⁵ = 32752 with it
Another format, the same recipe: normalise as the statement says, add the excess and place the bits.

c) −0.15625. 0.15625=0.00101=0.101⋅2−20.15625 = 0.00101 = 0.101 \cdot 2^{-2} (the point jumps 2 places right to sit in front of the first 1). Exponent −2+16=14=01110-2 + 16 = 14 = 01110; sign 1.

  • Without a hidden bit: mantissa 1010000000 → 1 | 01110 | 1010000000 = 1011 1010 1000 0000 = BA80.
  • With a hidden bit: mantissa 0100000000 → 1 | 01110 | 0100000000 = 1011 1001 0000 0000 = B900.

This number already came up in level 2, with 0.00101=1.01⋅2−30.00101 = 1.01 \cdot 2^{-3} in IEEE 754. Here the exponent is −2 for the same reason as in b): the point stays in front of the first 1, not behind it. With a hidden bit, the 1 of 0.101 is not stored: 01 is left and it is padded with zeros on the right, 0100000000.

Copying the exponent −3 from level 2. You store 13 = 01101 and, without a hidden bit, get B680, which in this format is −0.078125: half again.

In a format like this there is no way to write 0 (the mantissa always starts with 0.1) unless the statement reserves a code for it. IEEE 754 solves it with its special cases.

Practice quiz

Twenty questions to review the whole topic. They do not count for anything and you can repeat them as many times as you like; each one has its explanation. In the boxes, write hexadecimal in upper or lower case and binary numbers without spaces.

Question 1Single choice

How many bits does each field of an IEEE 754 single-precision number have (sign, exponent and mantissa)?

  1. 1, 8 and 23
  2. 1, 11 and 52
  3. 1, 7 and 24
  4. 1, 8 and 24
Solution

Answer: 1, 8 and 23

Single precision splits its 32 bits into 1 sign bit (bit 31), 8 exponent bits (bits 30 to 23) and 23 mantissa bits (bits 22 to 0).

Question 2Short answer

The real exponent of a number is 66. Which 8 bits are stored in the exponent field? Write them without spaces.

Solution

Answer: 10000101

In excess 127 we store 6+127=133=128+4+1=100001016 + 127 = 133 = 128 + 4 + 1 = 10000101.

Question 3Calculation

Fill in the stored exponent (in decimal) for each real exponent, in excess 127.

Real exponentStored exponent
6
-3
0
-126
Solution
Real exponentStored exponent
6133
-3124
0127
-1261

Add 127: 6+127=1336 + 127 = 133, −3+127=124-3 + 127 = 124, 0+127=1270 + 127 = 127 and −126+127=1-126 + 127 = 1, the smallest exponent of a normal number.

Question 4Short answer

Write the fractional part 0.3750.375 in binary (with the point, for example 0.1).

Solution

Answer: 0.011

0.375⋅2=0.750.375 \cdot 2 = 0.75 (0), 0.75⋅2=1.50.75 \cdot 2 = 1.5 (1), 0.5⋅2=10.5 \cdot 2 = 1 (1): 0.0110.011. Check: 0.25+0.125=0.3750.25 + 0.125 = 0.375.

Question 5Short answer

Give in hexadecimal (8 digits) the number −6.5-6.5 in IEEE 754 single precision.

Solution

Answer: C0D00000

6.5=110.1=1.101⋅226.5 = 110.1 = 1.101 \cdot 2^2. Sign 1, exponent 2+127=129=100000012 + 127 = 129 = 10000001, mantissa 101: 1 | 10000001 | 101000… = 1100 0000 1101 0000… = C0D00000.

Question 6Short answer

Which decimal number does the word 41100000 represent?

Solution

Answer: 9

0100 0001 0001 0000…: sign 0, exponent 10000010 = 130 → 3, mantissa 001 → 1.001. 1.001⋅23=10012=91.001 \cdot 2^3 = 1001_2 = 9.

Question 7True or false

Say whether each statement about IEEE 754 is true or false.

  1. The 1 left before the point after normalising is not stored in the mantissa.
  2. The IEEE 754 exponent is stored in two’s complement.
  3. Changing the sign of a number only changes bit 31.
  4. Every number with two decimal places fits exactly in single precision.
  5. The stored exponents 00000000 and 11111111 are reserved for special cases.
Solution
  • T — The 1 left before the point after normalising is not stored in the mantissa.
  • F — The IEEE 754 exponent is stored in two’s complement.
  • T — Changing the sign of a number only changes bit 31.
  • F — Every number with two decimal places fits exactly in single precision.
  • T — The stored exponents 00000000 and 11111111 are reserved for special cases.

The 1 is hidden; the exponent goes in excess 127, not two’s complement; the sign is a separate bit (sign-magnitude); 0.1 or 0.25 + 0.01 are not exact (only sums of powers of 2 are); and the exponents at the ends are reserved for zero, denormals, infinity and NaN.

Question 8Match

Match each 32-bit word with what it represents.

00000000
7F800000
7FC00000
00800000
3F800000

Definitions:

  • the smallest normal
  • positive zero
  • the largest number
  • one
  • plus infinity
  • NaN
Solution
  • 00000000 → positive zero
  • 7F800000 → plus infinity
  • 7FC00000 → NaN
  • 00800000 → the smallest normal
  • 3F800000 → one

All zeros is +0; exponent 11111111 with mantissa 0 is infinity and with a non-zero mantissa, NaN; 00800000 has exponent 00000001 and mantissa 0: 1.0⋅2−1261.0 \cdot 2^{-126}; 3F800000 has exponent 127 (real 0) and mantissa 0: 1. The largest number would be 7F7FFFFF.

Question 9Order

Put in order the steps to convert a decimal into IEEE 754 single precision in hexadecimal.

  1. Write the sign, the exponent e + 127 and the mantissa without the 1
  2. Convert the absolute value to binary (integer part by divisions, fractional part by multiplications)
  3. Normalise to 1.mantissa times 2 to the e
  4. Write one hexadecimal digit per group
  5. Join the 32 bits and group them in fours
Solution

Correct order:

  1. Convert the absolute value to binary (integer part by divisions, fractional part by multiplications)
  2. Normalise to 1.mantissa times 2 to the e
  3. Write the sign, the exponent e + 127 and the mantissa without the 1
  4. Join the 32 bits and group them in fours
  5. Write one hexadecimal digit per group

It is the four-step method of the theory: binary, normalise, fields and hexadecimal (the last one in two stages: group and translate).

Question 10Single choice

What is the stored mantissa of 1010011.01121010011.011_2?

  1. 010011011 followed by zeros
  2. 1010011011 followed by zeros
  3. 011 followed by zeros
  4. zeros followed by 010011011
Solution

Answer: 010011011 followed by zeros

1010011.011=1.010011011⋅261010011.011 = 1.010011011 \cdot 2^6: the mantissa is the digits after the point, 010011011, with zeros on the right up to 23 bits.

Question 11Fill in the gaps

Complete the sentence about normalising 0.00101.

To normalise 0.00101 the point moves ____ places to the ____, so the real exponent is ____ and the stored exponent starts with ____.

Words:

  • 3
  • 2
  • right
  • negative
  • positive
  • 1
  • left
  • 0
Solution

To normalise 0.00101 the point moves 3 places to the right, so the real exponent is negative and the stored exponent starts with 0.

0.00101=1.01⋅2−30.00101 = 1.01 \cdot 2^{-3}: three jumps to the right, exponent −3 and stored −3+127=124=01111100-3 + 127 = 124 = 01111100, which starts with 0.

Question 12Multiple · wrong ticks subtract

Which of these decimals are stored exactly in IEEE 754 single precision?

  1. 0.625
  2. 0.1
  3. 83.375
  4. 0.2
  5. 0.15625
Solution

Answer: 0.625 · 83.375 · 0.15625

A decimal is exact in binary if its fractional part is a sum of powers of 2 (and the bits fit). 0.1 and 0.2 are not and are rounded to the nearest float.

Question 13Single choice

When reading the word 00200000, what do you have to do?

  1. Treat it as a denormal: 0.mantissa times 2 to the −126
  2. Apply the normal formula with exponent −127
  3. It is zero
  4. It is NaN
Solution

Answer: Treat it as a denormal: 0.mantissa times 2 to the −126

00200000 has sign 0, exponent 00000000 and mantissa 01000…: denormal, 0.01⋅2−126=2−1280.01 \cdot 2^{-126} = 2^{-128}.

Question 14Calculation

Fill in the three fields of −27.5625=−1.10111001⋅24-27.5625 = -1.10111001 \cdot 2^{4} (exponent and mantissa in binary, without spaces; of the mantissa, only its first 8 bits).

SignExponentMantissa (first 8 bits)
Solution
SignExponentMantissa (first 8 bits)
11000001110111001

Sign 1 (negative); exponent 4+127=131=100000114 + 127 = 131 = 10000011; mantissa 10111001 followed by zeros. In hexadecimal, C1DC8000.

Question 15Short answer

Give in hexadecimal (8 digits) the number 100100 in IEEE 754 single precision.

Solution

Answer: 42C80000

100=11001002=1.1001⋅26100 = 1100100_2 = 1.1001 \cdot 2^6. Sign 0, exponent 133 = 10000101, mantissa 1001: 0 | 10000101 | 1001000… = 0100 0010 1100 1000… = 42C80000.

Question 16Single choice

What is the advantage of storing the exponent in excess instead of two’s complement?

  1. The order of the codes is the order of the exponents, and they are compared as unsigned numbers
  2. It allows larger exponents
  3. It avoids overflow
  4. It saves a bit
Solution

Answer: The order of the codes is the order of the exponents, and they are compared as unsigned numbers

In excess 127, 00000000 is the smallest exponent and 11111111 the largest: comparing exponents is comparing unsigned integers.

Question 17Short answer

The stopwatch stores a tenth of a second, 0.1, in single precision. Which hexadecimal does it store?

Solution

Answer: 3DCCCCCD

0.1=1.1001 1001…⋅2−40.1 = 1.1001\,1001\ldots \cdot 2^{-4}; exponent 123 = 01111011; the mantissa is cut at 23 bits and, since the leftover starts with 11, it is rounded up: …1101. Result 3DCCCCCD, slightly more than 0.1.

Question 18Short answer

Which decimal number does the word C1A00000 represent?

Solution

Answer: -20

1100 0001 1010 0000…: sign 1, exponent 10000011 = 131 → 4, mantissa 01 → 1.01. −1.01⋅24=−101002=−20-1.01 \cdot 2^4 = -10100_2 = -20.

Question 19Single choice

How many single-precision numbers are there strictly between 8 and 9?

  1. 220−12^{20} – 1
  2. 223−12^{23} – 1
  3. 2202^{20}
  4. Infinitely many
Solution

Answer: 220−12^{20} – 1

The numbers in [8,16)[8, 16) are 1.m⋅231.m \cdot 2^3; between 8 and 9 the first 3 mantissa bits are 000 and the other 20 are free: 2202^{20} numbers from 8 included, 220−12^{20} – 1 without it.

Question 20True or false

True or false: double precision, format changes and results that are too big.

  1. Double precision uses 11 exponent bits in excess 1023.
  2. Converting 0.1 from double to single precision loses nothing.
  3. 17.25 can be converted from double to single precision without losing anything.
  4. In IEEE 754 a result that is too big wraps around and comes out negative, as in two’s complement.
Solution
  • T — Double precision uses 11 exponent bits in excess 1023.
  • F — Converting 0.1 from double to single precision loses nothing.
  • T — 17.25 can be converted from double to single precision without losing anything.
  • F — In IEEE 754 a result that is too big wraps around and comes out negative, as in two’s complement.

Double has 1 + 11 + 52 bits and excess 210−1=10232^{10} – 1 = 1023. 0.1 is not exact and is rounded again when going down to 24 significant bits; 17.25 = 10001.01 fits in both. A result that is too big in floating point becomes infinity; it does not wrap around.

What next?

With this you have numbers with a point: how they are stored, how they are read and why some do not fit exactly. If you come from two’s complement, you have already seen the three ways of storing signed integers (sign-magnitude, ones’ complement and two’s complement) and now a fourth one, excess, inside the exponent.

In the practical part of IC1 you work with integers in the registers, but the topic helps you understand what you see in QtSpim: if you write .float 83.375 in the data segment, 42a6c000 appears in the Data tab, and QtSpim has system calls to print and read floats next to the integer and string ones you saw in System calls in MIPS. And when you want to test yourself with assembly, the IC1 practical mock exam has the structure of the real exam.

The next paper topic is Codes: BCD, Gray and ASCII/Unicode, other ways of storing information in binary that are not numbers to operate on.

To check your solutions, type the number or the word into the IEEE 754 explorer simulator; it also has the old 16-bit format from level 3, with and without a hidden bit, and its «Test yourself» section brings new numbers.

IC1 exam coming up?The theory and MIPS packs with new solved exams, their cheat sheets, blank exams and .s solutions, for free.See the pack

Cheat sheet: IEEE 754 floating point

The essentials in 30 seconds

  • Single precision: 1 + 8 + 23 = 32 bits; double: 1 + 11 + 52 = 64.
  • Normal value: (−1)s⋅1.mantissa⋅2e−127(-1)^s \cdot 1.\text{mantissa} \cdot 2^{e – 127}.
  • Storing: binary → normalise 1.…⋅2e1.\ldots \cdot 2^e → sign, e+127e + 127, mantissa without the 1 (zeros on the right) → hexadecimal in fours.
  • Reading: hexadecimal → binary → look at the exponent (special?) → e−127e – 127 and the 1 in front.
  • Stored exponent: starts with 1 if the number is ≥ 2, 01111111 if it is between 1 and 2, starts with 0 if it is < 1.

I want to…

I want to…HowResult
convert 0.375 to binarymultiply by 2: 0.75 → 0; 1.5 → 1; 1.0 → 10.011
normalise 1010011.011point 6 places to the left1.010011011⋅261.010011011 \cdot 2^6
store exponent 66+127=1336 + 127 = 13310000101
store exponent −3−3+127=124-3 + 127 = 12401111100
convert 83.375 to IEEE 7540 | 10000101 | 0100110110…42A6C000
read BE2000001 | 01111100 | 01… → −1.01⋅2−3-1.01 \cdot 2^{-3}−0.15625
know if a decimal is exactdoes the ×2 table reach 0?0.625 yes; 0.1 and 0.2 no
round a recurring numberlook at the first leftover bit (and the next ones)0.1 → 3DCCCCCD
change the signflip bit 313… ↔ B…, 4… ↔ C…

Values worth knowing

HexadecimalValue
00000000 / 80000000+0 / −0
3F8000001
3F0000000.5
400000002
7F800000 / FF800000+∞ / −∞
7FC00000NaN
008000002−1262^{-126}, the smallest normal
7F7FFFFFabout 3.4⋅10383.4 \cdot 10^{38}, the largest

Templates from the exercises

12.5      = 1100.1         = 1.1001 · 2^3     → 0 | 10000010 | 1001…   = 41480000
0.75      = 0.11           = 1.1 · 2^-1       → 0 | 01111110 | 1000…   = 3F400000
-27.5625  = -11011.1001    = -1.10111001 · 2^4 → 1 | 10000011 | 10111001… = C1DC8000
0.625     = 0.101          = 1.01 · 2^-1      → 0 | 01111110 | 01000…  = 3F200000

Symptom and likely cause

SymptomLikely cause
The hexadecimal of a normal number starts with 0 or 8you did not add 127 to the exponent
Reading your result gives a noticeably bigger numberthe hidden 1 is inside the mantissa
The last hexadecimal digits are not 0 for a simple numberthe mantissa is pushed to the right
A number less than 1 has a stored exponent starting with 1you counted the jumps of the point backwards
You get 7 or 9 hexadecimal digitsa bit is missing or extra (count 1 + 8 + 23)
When reading, an absurd number comes out with exponent 00000000 or 11111111it was a special case

Before handing in, ask yourself

  1. Have I added (or subtracted) 127 to the exponent?
  2. Have I left the hidden 1 out of the mantissa and padded with zeros on the right?
  3. Do I have 32 bits and 8 hexadecimal digits?
  4. Have I done the way back and do I get the number in the statement?
Keep goingAll Computers articles

Did this article help you? Here is how you can support SergioLearns →

Ready for the exam?IC1 practical mock exam — MIPS in QtSpim with other data, subroutines and keyboard input (and why part 1 decides almost everything)