How float,double data type is represented in the memory ?
Ans:
float : It is 32 bit data type.
23 bit : for mantissa
8 bit : for exponent ( including one signed bit of exponent )
1 bit : for signed bit of mantissa
e.g Memory representation of float a = -3.3f;
step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… = 1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010011 00110011 001100110 (only first 23 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : store 1 in the signed bit (green colour in the figure )
Step 6: Add 127 in the exponent and convert in the binary number form ( since in 7 bit of exponent except signed bit maximum possible number is 1111111 )
Exponent= 127+1=128
Binary form of 128 is 1000000 0
Store first bit i.e 0 at the 0 th position of exponent. (in figure red colour zero)
Store rest 7 bit at 1 to 7 bit of exponent from right to left (in figure red color 1 to 7)
Step 7: store the 23 bit mantissa at 1 to 23 bit position in as shown in figure .Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure and so on.
In the memory -3.3 is represent as :
double:
It is 64 bit data type.
52 bit : for mantissa
11 bit : for exponent (including one signed bit of exponent )
1 bit : for signed bit of mantissa
e.g Memory representation of double a = -3.3 ;
step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… = 1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010 01100110 01100110 01100110 01100110 01100110 01100110 (only first 52 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : store 1 in the signed bit (green colour in the figure )
Step 6: Add 1023 in the exponent and convert in the binary number form ( since in 10 bit of exponent except signed bit maximum possible number is 1111111111 )
Exponent= 1023+1=1024
Binary form of 1024 is 10000000000
Store first 4 bit i.e 0000 at the 0 to 3 position of exponent. (in figure blue colour digit)
Store rest 7 bit at 4 to 10 bit of exponent from right to left (in figure blue color 4 to 10)
Step 7: store the 52 bit mantissa at 1 to 52 bit position in as shown in figure .Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure and so on.
In the memory -3.3 is represented as :
Ans:
float : It is 32 bit data type.
23 bit : for mantissa
8 bit : for exponent ( including one signed bit of exponent )
1 bit : for signed bit of mantissa
e.g Memory representation of float a = -3.3f;
step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… = 1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010011 00110011 001100110 (only first 23 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : store 1 in the signed bit (green colour in the figure )
Step 6: Add 127 in the exponent and convert in the binary number form ( since in 7 bit of exponent except signed bit maximum possible number is 1111111 )
Exponent= 127+1=128
Binary form of 128 is 1000000 0
Store first bit i.e 0 at the 0 th position of exponent. (in figure red colour zero)
Store rest 7 bit at 1 to 7 bit of exponent from right to left (in figure red color 1 to 7)
Step 7: store the 23 bit mantissa at 1 to 23 bit position in as shown in figure .Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure and so on.
In the memory -3.3 is represent as :
double:
It is 64 bit data type.
52 bit : for mantissa
11 bit : for exponent (including one signed bit of exponent )
1 bit : for signed bit of mantissa
e.g Memory representation of double a = -3.3 ;
step1 : convert the number (3.3) into binary form
binary value of 3.3 is 11.0100110011001100110011001100110011…
step2 : convert the binary number in the scientific form
11.0100110011001100110011001100110011… = 1.10100110011001100110011001100110011…*10^1
Step4 : find exponent and mantissa and signed bit
Mantissa = .1010 01100110 01100110 01100110 01100110 01100110 01100110 (only first 52 bit )
Exponent= 1
Signed bit =1 ( Since a is negative number )
Step5 : store 1 in the signed bit (green colour in the figure )
Step 6: Add 1023 in the exponent and convert in the binary number form ( since in 10 bit of exponent except signed bit maximum possible number is 1111111111 )
Exponent= 1023+1=1024
Binary form of 1024 is 10000000000
Store first 4 bit i.e 0000 at the 0 to 3 position of exponent. (in figure blue colour digit)
Store rest 7 bit at 4 to 10 bit of exponent from right to left (in figure blue color 4 to 10)
Step 7: store the 52 bit mantissa at 1 to 52 bit position in as shown in figure .Store 1st bit of mantissa (from right to left ) i.e 1 at the position 1 of mantissa as in figure ,2nd bit of mantissa i.e 0 at the position 2 of mantissa as in figure and so on.
In the memory -3.3 is represented as :
0 comments:
Post a Comment