Convert binary floating-point real numbers into denary and vice versa
13.3 Floating‑Point Numbers, Representation and Manipulation
What is a Floating‑Point Number?
Think of a floating‑point number as a scientific notation that computers use. It looks like 1.23 × 10⁴ in maths, but in binary it is written as a sign, a mantissa (or significand), and an exponent.
IEEE‑754 32‑bit Format (Single Precision)
| Bits | Meaning |
|---|---|
| 1 | Sign bit (0 = positive, 1 = negative) |
| 8 | Exponent (bias 127) |
| 23 | Mantissa (fractional part) |
Converting Binary Floating‑Point to Denary (Decimal)
- Read the sign bit. If it is
1, the number is negative. - Convert the 8‑bit exponent to decimal and subtract the bias (127) to get the real exponent.
- Take the 23‑bit mantissa, prepend an implicit leading
1(unless the exponent is all zeros), and convert it to a fraction. - Combine everything:
value = (-1)^{sign} × 1.mantissa × 2^{exponent}.
Example: Binary 01000001001000000000000000000000
- Sign =
0→ positive. - Exponent bits =
10000010→ decimal130→ real exponent130-127 = 3. - Mantissa bits =
01000000000000000000000→ fraction0.25. - Value =
1.25 × 2³ = 10.0.
Converting Denary (Decimal) to Binary Floating‑Point
- Determine the sign bit:
0for positive,1for negative. - Write the number in binary scientific notation:
±1.xxxxx × 2^E. - Set the exponent field to
E + 127(bias 127) and write it as 8 bits. - Take the fractional part after the leading 1 and pad or truncate to 23 bits for the mantissa.
Example: Convert -5.75 to IEEE‑754 single precision.
- Sign bit =
1. - Binary of 5.75 =
101.11→ scientific form1.0111 × 2². - Exponent =
2 + 127 = 129→10000001. - Mantissa =
0111followed by zeros →01110000000000000000000. - Resulting 32‑bit pattern:
11000000101110000000000000000000.
Practice Problems
- Convert the binary floating‑point number
00111111011000000000000000000000to decimal. - Write the decimal number
12.5in IEEE‑754 single‑precision binary. - Explain why the exponent bias is necessary.
- What happens when the exponent field is all zeros?
Key Takeaways
- Floating‑point numbers use sign, exponent, and mantissa fields.
- The exponent bias (127 for single precision) allows representation of both positive and negative exponents.
- Conversion involves binary arithmetic and careful handling of the implicit leading 1.
- Understanding these steps helps debug precision errors in programming.
Quick Cheat Sheet
| Step | Action |
|---|---|
| 1 | Read sign bit. |
| 2 | Compute real exponent (exp − bias). |
| 3 | Build mantissa with implicit 1. |
| 4 | Combine: (-1)^{sign} × 1.mantissa × 2^{exponent}. |
Revision
Log in to practice.
2 views
0 suggestions