Memory representation of float data type in C.

Size of float data type is 32 bit. Its 32 bit is used as:
1. 23 bit: for mantissa
2. 8 bit: for exponent(including one signed bit of exponent)
3. 1 bit: for signed bit of mantissa
Memory representation of: float a = -3.3f;

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 = .1010011 00110011 001100110 (only first 23 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 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 0th position of exponent. (In figure red color zero)
Store rest 7 bit at 1 to 7 bit of exponent from right to left (in figure red color 1 to 7)

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

No comments: