Cs · Computer Science

How to Find the Mantissa in a Floating-Point Binary Number

Published By the 9to5Science editorial team

At a glance

  1. 1. Identify the format

    Determine whether the bits are an IEEE 754 value or an ordinary binary numeral; the mantissa is read differently in each case.

  2. 2. Split the fields

    For IEEE 754, separate the sign, exponent, and fraction fields using the format’s specified bit widths.

  3. 3. Restore the leading bit

    For a normal value, prepend an implicit 1 to the fraction field to get the significand.

  4. 4. Check special cases

    If the exponent field is all zeros or all ones, use the subnormal, zero, infinity, or NaN rules instead.

Title: How to Find the Mantissa in a Floating-Point Binary Number Category: computer-science

The word mantissa is used in two ways: it may mean the fraction bits stored in a floating-point number, or the complete significand used in its value. For a normal IEEE 754 binary number, the significand includes an implicit leading 1 that is not stored. Knowing which meaning is intended is the key to reading the bits correctly.

IEEE 754 fields

An IEEE 754 binary floating-point value is divided into a sign bit, an exponent field, and a fraction field. Binary32 (single precision) uses 1 sign bit, 8 exponent bits, and 23 fraction bits. Binary64 (double precision) uses 1, 11, and 52 bits, respectively.

For a normal value, the stored exponent is an unsigned integer EE. Subtract the format’s bias to get the actual exponent ee. The bias is 127 for binary32 and 1023 for binary64. The value is

(−1)s×(1.f)2×2E−bias,(-1)^s \times (1.f)_2 \times 2^{E-\text{bias}},

where ss is the sign bit and ff is the fraction field interpreted as bits after the binary point. The leading 11 in (1.f)2(1.f)_2 is implicit: it is part of the significand but does not appear in the stored fraction field.

If by “mantissa” you mean only the stored field, use ff. If you mean the complete significand, use (1.f)2(1.f)_2 for a normal value.

Worked example: decode a binary32 value

Consider this 32-bit pattern:

0 10000010 10110000000000000000000

The spaces separate the sign, exponent, and fraction fields.

  1. Sign: s=0s=0, so the number is positive.
  2. Exponent: 100000102=13010000010_2=130. For binary32, the bias is 127, so the actual exponent is 130−127=3130-127=3.
  3. Fraction: the field begins with 1011 and the remaining bits are zero. As a binary fraction, it is .10112=12+18+116=0.6875..1011_2=\frac{1}{2}+\frac{1}{8}+\frac{1}{16}=0.6875.
  4. Significand: restore the implicit leading 1: 1.10112=1+0.5+0.125+0.0625=1.68751.1011_2=1+0.5+0.125+0.0625=1.6875.
  5. Value: multiply by 232^3 to get 1.6875×8=13.51.6875\times8=13.5.

So the stored fraction (sometimes called the mantissa) is 1011000…, the significand is 1.101121.1011_2, and the represented value is 13.5.

If the input is an ordinary binary number

A written binary numeral with a binary point is not necessarily an IEEE 754 bit pattern. To find its significand for a nonzero value, move the binary point until one nonzero digit remains to its left, then record how far it moved as the power of 2.

For example,

1101.1012=1.1011012×23.1101.101_2=1.101101_2\times2^3.

Here the significand is 1.10110121.101101_2, and the exponent is 3. This is a mathematical normalization, not a process of splitting IEEE 754 fields. For a value smaller than 1, the exponent can be negative; for example, 0.001012=1.012×2−30.00101_2=1.01_2\times2^{-3}.

Subnormal values and special encodings

The implicit leading 1 applies only to normal values. If the exponent field is all zeros, the value is zero when the fraction is also all zeros. Otherwise it is subnormal, and the significand is 0.f0.f rather than 1.f1.f. Its exponent is fixed at 1−bias1-\text{bias}, so a binary32 subnormal has value

(−1)s×(0.f)2×2−126.(-1)^s\times(0.f)_2\times2^{-126}.

If the exponent field consists entirely of ones, a zero fraction represents infinity, and a nonzero fraction represents a NaN (not a number). These encodings do not have an ordinary finite mantissa-and-exponent interpretation.

Common mistakes

  • Forgetting the hidden bit: normal values use 1.f1.f, not just ff, as their significand.
  • Using the stored exponent directly: subtract the bias before treating the exponent as a power of 2.
  • Adding a hidden 1 to a subnormal: exponent-field zero means the significand starts with 0.
  • Confusing a bit pattern with a written numeral: 1101.101 is a binary number, while a 32-bit string divided into sign, exponent, and fraction fields is an encoded floating-point value.
  • Assuming the fraction is the original decimal digits: floating-point stores a rounded binary value when the exact number cannot be represented. Decoding recovers the stored value, which may differ slightly from the decimal input used to create it.

References

  1. IEEE Standard for Floating-Point Arithmetic (IEEE 754-2019)
  2. What Every Computer Scientist Should Know About Floating-Point Arithmetic — David Goldberg

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.