Integers alone are not enough for scientific or business computing. This section shows how computers store very large, very small and fractional numbers by borrowing the idea of scientific notation, first with the lecture’s simple 14-bit model, then with the real-world IEEE 754 standard (Null & Lobur, Ch. 2).
Why Floating Point?
With 16-bit two’s complement integers the largest value is +32,767. Two everyday needs break this immediately:
Large values: how do we store 32,000,000?
Fractions: how do we store 9.625?
The answer is floating-point representation, which is scientific notation in binary: 32,000,000=32×106 needs only the digits “32” and the exponent “6”.
Floating-point calculations can be done using only integer hardware, by software that stores the parts separately and manipulates them. This is called floating-point emulation (floating-point values are not stored as such; programs make it seem as if they are). Most of today’s computers instead have specialized floating-point hardware (an FPU), which is far faster.
the significant digits; its length sets the precision
Exponent
the power of the base; its size sets the range
The radix point “floats”: the same number can be written many ways (17=17.0×100=1.7×101=0.17×102), and the exponent records where the point really is. In binary, 17=100012×20=1000.12×21=⋯=1.00012×24.
Normalization
To make the representation unique and use the significand bits efficiently, numbers are normalized: the exponent is adjusted so there are no leading 0s, giving the form
1.xxxxxxxx×2yyyy
For example 0.01×2−1=0.1×2−2=1.0×2−3.
Shifting rule: moving the binary point left by k places addsk to the exponent; moving it right by k places subtractsk. Example: 1001.101=1.001101×23 (point moved left 3).
Since a normalized nonzero binary number always starts with “1.”, that 1 need not be stored. Only the fraction bits after the point are kept; the leading 1 is implicit (a “hidden bit”), which gains one bit of precision for free.
The Lecture’s 14-bit Model
Field
Bits
Contents
Sign
1
0 = positive, 1 = negative
Exponent
5
power of 2
Significand
8
the 8 fraction bits after the implicit leading 1
13sign (1 bit)
12–8exponent (5 bits)
7–0significand (8 bits)
Step 1: the simple (unbiased) model
Store the exponent as a plain unsigned 5-bit number. For 17=1.0001×24: sign 0, exponent 4=00100, fraction 0001 padded to 8 bits =00010000:
17→00010000010000
Disadvantage: a 5-bit unsigned field only holds 0 to 31, so there is no way to store a negative exponent, e.g. 1.0001×2−4. Every small number (between 0 and 1) is impossible.
Step 2: the biased (excess-16) model
To allow negative exponents, store the exponent plus a fixed bias. With 5 bits there are 32 values (0 to 31); choosing the bias near the middle, 16, gives an excess-16 representation:
Advantage: biased exponents are plain unsigned numbers, so comparing or sorting floating-point values is easier and faster: a larger true exponent always has a larger stored pattern. For example −1→15=01111 and −2→14=01110; since 01111>01110 as unsigned numbers, −1>−2 is preserved.
Mini-example
17=1.0001×24: stored exponent 16+4=20=10100, so 17→01010000010000.
−1.0100×2−9: sign 1, stored exponent 16−9=7=00111, fraction 01000000, so it is stored as 10011101000000.
Procedure: decimal → 14-bit (excess-16)
Sign bit: 0 if positive, 1 if negative. Work with the absolute value from now on.
Convert to binary (integer part by division, fraction part by multiplication).
Normalize to 1.f×2e.
Exponent field =e+16 in 5-bit binary (must lie in 0 to 31).
Significand field = the bits of f, padded with 0s on the right (or truncated) to 8 bits.
The IEEE 754 Standard
Set by the Institute of Electrical and Electronics Engineers (IEEE) in 1985, to make floating-point programs portable between processors and to encourage numerically oriented software. It uses the same ideas as the 14-bit model: sign, biased exponent and fraction with an implicit leading 1.
Format
Total
Sign
Exponent
Fraction
Bias
Special exponent
Single precision
32 bits
1
8
23
127
255 (all ones)
Double precision
64 bits
1
11
52
1023
2047 (all ones)
The value of a normal number is
(−1)S×(1.F)2×2E−bias
where S is the sign bit, E the stored (biased) exponent and F the stored fraction.
31sign (1 bit)
30–23exponent (8 bits)
22–0fraction (23 bits)
Single precision (32 bits)
63sign (1 bit)
62–52exponent (11 bits)
51–0fraction (52 bits)
Double precision (64 bits)
Special values (single precision; for double replace 255 by 2047):
Exponent E
Fraction F
Meaning
0
0
zero: +0 if S=0, −0 if S=1 (two zeros)
1 to 254
anything
normal number (−1)S×1.F×2E−127
255
0
infinity: +∞ or −∞ depending on S
255
nonzero
NaN (“not a number”), flags an error, e.g. 0/0 or −1
Because zero has two representations (+0 and −0) and because results are approximations, programmers should avoid testing a floating-point value for equality to zero (see section 2.5).
Procedure: decimal → IEEE single
Sign bit S.
Convert ∣x∣ to binary and normalize to 1.f×2e.
E=e+127 as an 8-bit unsigned number.
F = bits of f, padded to 23 bits.
Write SEF as 32 bits and group into 4s for hex.
Procedure: IEEE single → decimal: expand the hex into 32 bits, split 1∣8∣23, check for special values, otherwise compute (−1)S×1.F×2E−127.
Store 1710 in the lecture’s 14-bit floating-point model (a) with an unsigned (unbiased) exponent and (b) with an excess-16 exponent. Why was the bias introduced?
Show solution ↓Hide solution ↑
Solution
Convert and normalize: 17=16+1=100012=1.00012×24 (point moved left 4 places).
Sign: positive → 0
Fraction after the leading 1: 0001 → padded to 8 bits: 00010000
(a) Unbiased: exponent field =4=00100.
17→00010000010000
(b) Excess-16: exponent field =4+16=20=10100.
17→01010000010000
Check (b): exponent 20−16=4; significand 1.00012=1.0625; value 1.0625×16=17 ✓.
Why a bias? An unsigned exponent field cannot hold negative exponents, so numbers like 1.0001×2−4 (anything smaller than 1) could not be stored. With excess-16, stored values 0 to 15 mean exponents −16 to −1. The bias also keeps exponent fields unsigned, so magnitudes compare like ordinary binary numbers (fast sorting/comparison).
Exercise 2
Express each value in the 14-bit model with an excess-16 exponent:
(a)9.625(b)−0.375(c)−1.01002×2−9 (also give its decimal value)
Show solution ↓Hide solution ↑
Solution
(a)9=10012; 0.625: 0.625×2=1.25→1, 0.25×2=0.5→0, 0.5×2=1.0→1, so 0.625=0.1012.
9.625=1001.1012=1.0011012×23
Sign 0
Exponent 3+16=19=10011
Fraction 001101 → 00110100
Answer: 01001100110100. Check: 1.0011012=1+81+161+641=1.203125, and 1.203125×8=9.625 ✓.
(b)0.375: 0.375×2=0.75→0, 0.75×2=1.5→1, 0.5×2=1.0→1, so 0.375=0.0112=1.12×2−2 (point moved right 2).
Sign 1
Exponent −2+16=14=01110
Fraction 1 → 10000000
Answer: 10111010000000. Check: −1.5×2−2=−0.375 ✓.
(c) Already normalized.
Sign 1
Exponent −9+16=7=00111
Fraction 0100 → 01000000
Answer: 10011101000000. Decimal value: 1.01002=1.25, so −1.25×2−9=−1.25/512=−0.00244140625.
Exercise 3
Each pattern is in the 14-bit excess-16 model. Find its decimal value.
(d)S=0; exponent 01100=12, true −4; significand 1.100110012=1+256153=1.59765625.
1.59765625/16=0.099853515625. This is the closest the model gets to 0.1 (by truncation), a first taste of the precision limits discussed in section 2.5.
Exercise 4
In the excess-16 model:
(a) Give the stored exponent field for true exponents −1, −2, 5 and 6, and show that comparing the stored fields as unsigned numbers gives the correct order.
(b) What range of true exponents can be stored? What is the largest positive value of the 14-bit model?
Show solution ↓Hide solution ↑
Solution
(a) Stored = true +16:
True exponent
Stored (decimal)
Stored (binary)
−2
14
01110
−1
15
01111
5
21
10101
6
22
10110
As unsigned numbers 01110<01111<10101<10110, which is exactly −2<−1<5<6. With a two’s complement exponent instead, −1 would be 11111 and would wrongly look larger than 6=00110.
(b) The 5-bit field holds 0 to 31, so true exponents are 0−16=−16 up to 31−16=+15.
Largest positive value: sign 0, largest exponent 11111 (+15), all fraction bits 1:
(b) With 11 exponent bits and bias 1023, true exponents go up to about ±1023, so magnitudes reach roughly 21024. Converting to a power of 10, solve 21024=10x:
x=1024log102≈1024×0.30103≈308.25
So doubles span roughly 10−308 to 10308 in magnitude. Anything beyond is overflow; anything nonzero but closer to 0 than about 10−308 is underflow.
Single precision (8-bit exponent, largest true exponent 254−127=127): largest value =(2−2−23)×2127≈3.4×1038; the smallest normal positive value is 2−126≈1.18×10−38.