views:

49

answers:

2

In learning how floating point numbers are represented in computers I have come across the term "bias value" that I do not quite understand.

The bias value in floating point numbers has to do with the negative and positiveness of the exponent part of a floating point number.

The bias value of a floating point number is 127 which means that 127 is always added to the exponent part of a floating point number. How does doing this help determine if the exponent is negative or positive or not?

+2  A: 

In single precision floating point, you get 8 bits in which to store the exponent. Instead of storing it as a signed two's complement number, it was decided that it'd be easier to just add 127 to the exponent (since the lowest it could be in 8 bit signed is -127) and just store it as an unsigned number. If the stored value is greater than the bias, that means the value of the exponent is positive, if it's lower than the bias, it's negative, if it's equal, it's zero.

b0lt
+5  A: 

b0lt has already explained how bias works. At a guess, perhaps you'd like to know why they use a bias representation here, even though virtually all modern computers use two's completely essentially everywhere else (and even machines that don't use two's complement, use one's complement or sign-magnitude, not bias).

One of the goals of the IEEE floating point standards was that you could treat the bits of a floating point number as a (signed) integer of the same size, and if you compared them that way, the values will sort into the same order as the floating point numbers they represented.

If you used a twos-complement representation for the exponent, a small positive number (i.e., with a negative exponent) would look like a very large integer because the second MSB would be set. By using a bias representation instead, you don't run into that -- a smaller exponent in the floating point number always looks like a smaller integer.

FWIW, this is also why floating point numbers are typically arranged with the sign first, then the exponent, and finally the significand in the least significant bits -- this way, if you view those bits as an integer, the exponent is treated as more significant than the significand, so you don't get (for example) 0.9 sorting larger than 1.0.

Jerry Coffin
Yes, I also wanted to know why. This answers that. Very interesting. Thank you.
mudge