In c language the size of float in bytes is four, which is an equal to 32 bits.
These 32 bits are divided in 3 parts:
1. Sign bit: Single bit to store the sign i.e. 0 will represent positive and 1 will represent negative.
2. Exponent bits: In float we will be using 8 bits to store the exponents.
3. Mantissa bits: remaining 23 bits are used to store mantissa
An example of number representation:
Let the number be 5.5
Now the binary equivalent of the same will be (101.1)2
In the floating point representation we represent the number between 1 and 2.
This is done by representing in scientific notation as
(1.011)2 X 22
We get this notation similarly we do in math ie 1.011 X 100 which is the equivalent of 4 or 22.
Sign à 0
Exponent à 00000010
Mantissaà 0110000000000000.0000 upto 23 bits
here we have not written 1 before fraction as it is understood .
Range of float
We know that we have exponent of 8 bits so the range comes out to be from 0 to 255 or in sign magnitude it can be written as -127 to 128.
0 and 255 are used to store non normalized data (Data with less accuracy).
Now the range of exponent is from -126 to 127.
The smallest Positive number that can be represented:
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
±
|
Exponent bits
|
Mantissa bits
| |||||||||||||||||||||||||||||
it comes to be 1.0 X 2-126
1.0 is the mantissa
-126 is the signed decimal representation of exponent bits.
So the smallest number that can be represented will be 2-126 or it is equal to 1.17549E-38.
The largest Positive number that can be represented:
0
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
±
|
Exponent bits
|
Mantissa bits
| |||||||||||||||||||||||||||||
It comes to be (2.0 – 2-23 )X 2127
Mantissa can be considered as 2, as 2-23 is very small in magnitude.
127 is the signed decimal representation of exponent bits.
So the smallest number that can be represented will be 2 X 2127 or it is equal to 3.40282E+38.
Range of Float comes out to be ±3.40282E+38
No comments:
Post a Comment