CSC 284 · Introduction to Logic Design
Our notes
1 min readWhy floating point?
Fixed point cannot hold both very large and very small numbers. Floating point stores a number like scientific notation: value = (−1)^sign × mantissa × 2^exponent.
Normalisation
Move the binary point until there is a single 1 in front of it. 1011.01₂ = 1.01101 × 2³. Because the leading bit of a normalised binary number is always 1, IEEE 754 does not store it (the hidden bit).
IEEE 754 single precision (32 bits)
- Sign: 1 bit.
- Exponent: 8 bits, stored with a bias of 127 (stored value = true exponent + 127).
- Fraction (mantissa): 23 bits after the hidden 1.
Double precision uses 1 + 11 + 52 bits with a bias of 1,023.
Worked example: decimal to IEEE 754
Store −13.25.
- 13.25 = 1101.01₂ = 1.10101 × 2³.
- Sign = 1. Exponent = 3 + 127 = 130 = 1000 0010.
- Fraction = 10101 followed by eighteen 0s.
- Bits: 1 10000010 10101000000000000000000 = C1540000₁₆.
Worked example: IEEE 754 to decimal
Decode 0 01111110 10000000000000000000000.
- Sign 0 (positive). Exponent 126 − 127 = −1. Mantissa 1.1₂ = 1.5.
- Value = 1.5 × 2⁻¹ = 0.75.
Special values
- Exponent all 0s and fraction 0: zero (+0 and −0 exist).
- Exponent all 0s, fraction not 0: very small "denormal" numbers.
- Exponent all 1s, fraction 0: ±infinity (from 1 ÷ 0).
- Exponent all 1s, fraction not 0: NaN ("not a number", from 0 ÷ 0).
Precision and rounding
Single precision gives about 7 significant decimal digits; double gives about 15 to 16. Numbers like 0.1 are stored rounded, so comparing floats for exact equality is risky: test whether the difference is very small instead.
Range
The largest single-precision number is about 3.4 × 10³⁸; the smallest normalised positive one is about 1.18 × 10⁻³⁸.
Fixed against floating point
Floating point gives range at the cost of more complex hardware and rounding error; fixed point is exact within its small range and simpler.
Exams usually ask
- Convert a decimal number to IEEE 754 single precision and back.
- Explain bias, normalisation and the hidden bit.
Common mistake
Storing the true exponent instead of exponent + 127, or including the hidden 1 in the 23 fraction bits.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
IEEE 754
(opens en.wikipedia.org in a new tab)
Wikipedia, IEEE 754, CC BY-SA 4.0 · licence
-
Floating-point arithmetic
(opens en.wikipedia.org in a new tab)
Wikipedia, Floating-point arithmetic, CC BY-SA 4.0 · licence
Watch
-
Best pick IEEE Standard for Floating-Point Arithmetic (IEEE 754)
9 min · ≈ 41 MB · about ₦23
(opens youtube.com in a new tab)
-
Floating Point Numbers: IEEE 754 Standard | Single Precision and Double Precision Format
22 min · ≈ 99 MB · about ₦56
(opens youtube.com in a new tab)
-
Floating Point Numbers - Computerphile
9 min · ≈ 41 MB · about ₦23
(opens youtube.com in a new tab)
-
How Floating-Point Numbers Are Represented
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
Lecture 38 : FLOATING-POINT NUMBERS
32 min · ≈ 144 MB · about ₦81
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.