Real Number Representation in C

  • In C, float and double will store using IEEE 754 standard in a memory location.
  • Float – Called as a single precision real number (1 word = 4 bytes = 32 bit).
  • Double – Called as a double precision real number (2 words = 8 bytes = 64bit).
  • All real number’s process is done by small processor we call as a CPU.

Table 1. Three different type of bits to store flat and double.

Untitled Diagram (7).jpg

  • There are three parts of memory where float and double stored are there i.e. Sign, Exponent, Significant.

Untitled Diagram (5) (1).jpg

Steps to Convert real number data into memory :

  1. Convert into binary.
  2. Convert that binary data into standard binary.

i.e.   1.xe-+y

Ex : 1010. 0101

= 1.0100101 e+3

3. Add or Subtract exponent part with standard bias number.

[ float – 7F,  double – 3FF]

4. The result of 3rd step we have to put into exponent part.

5. Significant part is filled in significant part.

 

Now we will take one float and one double example :

  1. Float f = 1;

Untitled Diagram (5) (2).jpg

Step 1. Binary of 1  =  0000  0000  0000  0001

Step 2. Standard binary = 1.0e0

Step 3. Add or subtract from bias number = 7F – 0 = 7F

Step 4.  Final 1.0e0

 

2.Float f = 7.7

Step 1. Binary of 7.7 =  0111.10110

Step 2. Standard binary = 1.1110110e+2

Step 3. Add or subtract from bias number = 7F + 2= 81   <—this is hex number

Step 4.  Final 1.1110110e+2

 

Untitled Diagram (5) (3).jpg

 

Now we will do the same thing for double :

  1. Double d = 23.5   (remember double is a 64bit wide).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: