Reputation: 31
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
Reputation: 223484
In the bits 0 1110 00001 that represent a floating-point number:
These bits are interpreted:
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).
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
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