In computer Memory every data is represented in the form of binary bits. i.e. in the form of 0 and 1.
To represent floating point numbers i.e. decimal numbers the memory will follow some special rules to store and recognise these numbers. To understand the memory representation of decimal numbers we need to understand the following things –
1.Normal Scientific Form
2.Bias Value and how to calculate bias value.
First we will understand the floating point number for 8 bit of data.
Let us take an example,
So to write it in normal scientific form –
In normal scientific form always there is one digit at the left side of decimal , so here we will write 1.0×10-2
And now understand the memory representation –
8 bits –
Next 3 bits are exponent bits. To calculate the values of these bits, let understand by an example,MSB bit is here the sign bit and it is 0 for +ve number and it is 1 for –ve number.Here the number is positive , so the bit is 0.
Here our exponent value is -2. So the computer will not understand the –ve numbers. To store this number , the system will compute a bias value.
Bias Value is the value that will make it positive and it is calculated by 2^n-1, where n is the number of exponent bits. Here n is 3.
So bias value = 23-1 = 4.
Add this to the exponent i.e. -2+4 = 2.
So we write 0 1 0 in these bits i.e. (binary of 2 – 010.)
And from bit 0 to 3 ,called mantissa bits., This value is calculated from normal scientific form i.e. left side value from decimal, here this value is 1.
So we just write the binary of 1 here.
This is for 8 bit number, If we use 32 bit number then all steps are exactly same to store the number in memory.
Last 31 bit is for sign bit and 0 to 21 are mantissa bits and 22 to 30 are the exponent bits.