DrPhil7268
DrPhil7268

Reputation: 31

Mantissa Significant Bits

I'm just a tad confused about Mantissa bits.

On my practice exam I am asked to convert decimal to floating point. Working in terms of 1 sign bit, 4 exp bits and 5 mantissa bits, the number 132 is represented below according to our answer key as:

0 1110 00001

For the representation above, my actual mantissa bits were 0000100.

Since I'm only given 5 bits for Mantissa, does this mean we only count the leftmost five bits, and discard anything after?

If I had 0000101 for some other number, for example, would I discard the last two bits, it being still 00001? Thank you!

Upvotes: 3

Views: 2976

Answers (2)

Eric Postpischil
Eric Postpischil

Reputation: 223484

Decoding a Floating-Point Representation

In the bits 0 1110 00001 that represent a floating-point number:

  • 0 is the sign bit s.
  • 1110 is the exponent field e. (This is not the exponent; it is an encoding of the exponent.)
  • 00001 is the significand1 field f. (This is not the significand; it is an encoding of the significand.)

These bits are interpreted:

  • The sign bit s is used in (−1)s to give the sign. For 0, (-1)0 = +1, so the number represented is positive.
  • The exponent field e is adjusted by subtracting a bias to give the actual exponent. The question does not state what to use for the bias, but we can figure it is 7 as that is what it would be by the IEEE-754 pattern. For exponent field 1110, which is binary for 14, the actual exponent is 14−7 = 7. This means the number represented will be scaled by 27.
  • As long as the exponent field is not all zeros or all ones, the significand field f is interpreted by writing “1.”, appending the bits of the significand field, and interpreting that as a binary numeral.2 For bits 00001, we have 1.00001, which is 1 + 1/32. This is the significand F.
  • All together, the number represented is (−1)s • 2e−7F = +1 • 27 • (1 + 1/32) = 128 • (1 + 1/32) = 128 + 4 = 132.

Encoding a Floating-Point Representation

To encode 00000101, we do not start at the first bit given. We find the first significant digit, which, for binary, is first 1 bit. In 00000101, the first 1 bit is at position 2 (corresponding to value 22). Then, to form the significand, we take six bits from there, not five. The significand field is five bits, but the significand is six bits, because, for numbers in the normal range, it includes a leading one bit that is encoded via the exponent field. In 00000101, the six bits we need for the significand are 101000. The latter three bits are implicit. So the significand is 1.01000.

To encode this number, which is positive, has exponent 2, and has significand 1.01000, we use 0 for the sign bit, 2+7 for the exponent field, and 01000 for the significand field, so the encoding is 0 1001 01000.

If there were non-zero bits after the first six significant digits in the number, the actual number cannot be represented in this floating-point format. In that case, we can either declare an error that the conversion cannot be done or we can round the number to the nearest representable value. Most often, the rounding is done by rounding the number to the nearest representable value—if the bits after what fits in the significand start with 0, round down. If they start with 1 and include at least one more 1 somewhere, round up. If they start with 1 and all digits after that are zeros, then the number is halfway between two representable values, and the usual rule is to choose the representable value with the even low digit (make the last digit of the significand 0).

Footnotes

1 “Significand” is the preferred term for the fraction portion (versus exponent or sign) of a floating-point number. “Mantissa” is an old term for the fraction part of a logarithm. Mantissas are logarithmic; adding to the mantissa multiplies the number represented. Significands are linear; multiplying the significand multiplies the number represented.

2 If the exponent field e is all zeros, then it represents an exponent of 1 minus the bias and the significand field is interpreted as “0.” followed by the bits of the field, instead of “1.”.

Upvotes: 10

Gokul Thiagarajan
Gokul Thiagarajan

Reputation: 830

If the mantissa does not fit in the space reserved for it, it has to be rounded off.

https://www.doc.ic.ac.uk/~eedwards/compsys/float/

You may go through on rounding process using this,

How to perform round to even with floating point numbers

Upvotes: 2

Related Questions