# 8-bit floating-point representation

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:

"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 ?

• 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.
– D.W.
Mar 11 '16 at 11:55
• So, why 7 should be added? Mar 11 '16 at 12:01
• If you've understood the answer to your first question, I encourage you to edit your post to show what you do understand.
– D.W.
Mar 11 '16 at 12:04

## 1 Answer

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.

• 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. Mar 11 '16 at 12:34
• 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. Mar 11 '16 at 12:56
• Yes, you are right. This is a design decision that the instructor has implemented it through the tutorial and isn't a strict constraint. Mar 11 '16 at 13:12
• 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. Mar 11 '16 at 17:24
• @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) Oct 19 '17 at 19:28