1
$\begingroup$

I'm studying about representing fractional numbers as floating-point values. It is going to be an 8-bit representation. Somewhere in the text, it is said that:

8-bit floating-point representation

"We use the first bit to represent the sign (1 for negative, 0 for positive), the next four bits for the sum of 7 and the actual exponent (we add 7 to allow for negative exponents), and the last three bits for the mantissa's fractional part"

Now the question is: Why "7" -and not another value- must be added to the actual exponent ?

$\endgroup$
3
  • $\begingroup$ Welcome to CS.SE! The text hints at why, in the parenthetical. Incidentally, if you don't understand the explanation in one text, it's often helpful to search for a different explanation of the subject. There are many resources on floating point. $\endgroup$
    – D.W.
    Mar 11, 2016 at 11:55
  • $\begingroup$ So, why 7 should be added? $\endgroup$
    – Dsaki
    Mar 11, 2016 at 12:01
  • $\begingroup$ If you've understood the answer to your first question, I encourage you to edit your post to show what you do understand. $\endgroup$
    – D.W.
    Mar 11, 2016 at 12:04

1 Answer 1

3
$\begingroup$

With 4 bits you can represent 16 different values: 0,1,...,15. If you want to allow negative exponents it makes sense to take (approximately) half of the possible values to mean a negative exponent. By adding 7 to the exponent you map the values -7,-6,...,0,1,...,8 to the representable range. You might also want to look up two's complement.

$\endgroup$
5
  • $\begingroup$ So adding 7 , maps -7,-6,...,-1 to their corresponding positive values and adding a value more than 7 results in an out-range value which is incorrect. By the same reason, adding less than 7 to the exponent doesn't fix the problem. Thanks, I've got what I was looking for. $\endgroup$
    – Dsaki
    Mar 11, 2016 at 12:34
  • 1
    $\begingroup$ Adding different numbers changes which negative and which positive exponents you support. It's a design decision. Maybe just supporting -1 is enough for your application. $\endgroup$
    – adrianN
    Mar 11, 2016 at 12:56
  • $\begingroup$ Yes, you are right. This is a design decision that the instructor has implemented it through the tutorial and isn't a strict constraint. $\endgroup$
    – Dsaki
    Mar 11, 2016 at 13:12
  • 2
    $\begingroup$ The decision to use an offset instead of 2's complement IIRC was to keep the inverse of the smallest value smaller than the largest value, ie to avoid overflows. It was carefully chosen, in other words. $\endgroup$
    – KWillets
    Mar 11, 2016 at 17:24
  • $\begingroup$ @KWillets : The offset also allows zero to be represented as zeros and allows to use integer comparisons for comparing floating point numbers (excluding the sign bit) $\endgroup$
    – TEMLIB
    Oct 19, 2017 at 19:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.