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)

  1. Read the sign bit. If it is 1, the number is negative.
  2. Convert the 8‑bit exponent to decimal and subtract the bias (127) to get the real exponent.
  3. Take the 23‑bit mantissa, prepend an implicit leading 1 (unless the exponent is all zeros), and convert it to a fraction.
  4. Combine everything: value = (-1)^{sign} × 1.mantissa × 2^{exponent}.

Example: Binary 01000001001000000000000000000000

  • Sign = 0 → positive.
  • Exponent bits = 10000010 → decimal 130 → real exponent 130-127 = 3.
  • Mantissa bits = 01000000000000000000000 → fraction 0.25.
  • Value = 1.25 × 2³ = 10.0.

Converting Denary (Decimal) to Binary Floating‑Point

  1. Determine the sign bit: 0 for positive, 1 for negative.
  2. Write the number in binary scientific notation: ±1.xxxxx × 2^E.
  3. Set the exponent field to E + 127 (bias 127) and write it as 8 bits.
  4. 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 form 1.0111 × 2².
  • Exponent = 2 + 127 = 12910000001.
  • Mantissa = 0111 followed by zeros → 01110000000000000000000.
  • Resulting 32‑bit pattern: 11000000101110000000000000000000.

Practice Problems

  1. Convert the binary floating‑point number 00111111011000000000000000000000 to decimal.
  2. Write the decimal number 12.5 in IEEE‑754 single‑precision binary.
  3. Explain why the exponent bias is necessary.
  4. 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