In IEEE 754 format, we add the power of 2 value with the bias value (127 for 32bit) to get the exponent......what is bias? why is this bias necessary?
pls explain... thanks in advance....
Bias in IEEE754 is a nice little trick that allows us to do comparative operations (=, <, > etc) without scaling and normalising the floating point numbers.
Basically, we want to represent the magnitude of the number with an exponent, i.e. mantissa * 2^exponent. In single precision IEEE754 we have 8 bits to represent this exponent which takes values between -127 and 128. This range of numbers could be encoded using 2's complement, but representing it as unsigned with an implied bias allows us to do single instruction cycle compares of floating point numbers.
This applet is good to play around with if you are learning: **broken link removed**
Let me know if anything there doesn't make sense and I'll get back with more detail...
Basically, we want to represent the magnitude of the number with an exponent, i.e. mantissa * 2^exponent. In single precision IEEE754 we have 8 bits to represent this exponent which takes values between -127 and 128. This range of numbers could be encoded using 2's complement, but representing it as unsigned with an implied bias allows us to do single instruction cycle compares of floating point numbers.
-127 or 123 .. anyway the processor is going to convert it to binary..... similarly in 2^value, adding the value(+ve or -ve) with bias(127) yields the same 8-bit binary combination as in the range -128 to 127..
for eg: for 2^3, 127+3=130= 1000 0010 which is -126( 2's complement)...
how does it helps in comparisons......?
In a CPU you have an ALU (Arithmetic Logic Unit), this device can only do integer arithmetic. i.e. with numbers like 1, 243, -42... not 4.52 or -7.6 x 10^-3 etc
To work with numbers like 4.52, you need an FPU (floating point unit) hardware. FPUs are much slower than ALUs.
Remember, IEEE754 uses a sign bit.
As a result of using bias, if you read the interpret the 1's and 0's of a IEEE754 number as an integer number during comparison operations you'll get the correct answer.
Comparison operations for IEEE754 numbers are done in the ALU, NOT the FPU.