Memory representation of double in C


Memory representation of double in c programming language

Size of double is 64 bit. This is used as:

1. 52 bit: for mantissa
2. 11 bit: for exponent (including one signed bit of exponent)
3. 1 bit: for signed bit of mantissa

Memory representation of: double a = -3.3;

For this you have to follow following steps:


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


Step3: 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)


Step4: store 1 in the signed bit (green color in the figure)

Step 5: 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 represented as blue color digit)
Store rest 7 bit at 4 to 10 bit of exponent from right to left (in figure blue color 4 to 10)

Step 6: 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


If you have any questions on above Memory representation of double in c, you can ask here.

2 comments:

Unknown said...

where to put sign bit of Exponent

Unknown said...

@vinod kumar Prajapati : This is why you add 1023 to the exponent : so that negative exponents are convertible (e.g. if your exponent is -2, you will store 1023-2=1021). Why we do that and don't just put a signed bit ? Because it's the standard.