Computer Oriented Numerical Methods (BCA) 3rd Sem Previous Year Solved Question Paper 2022

Practice Mode:
2.

How a floating point number is stored in the memory of a computer ? Explain by taking suitable example.

Explanation

Floating-point numbers are typically stored in a computer's memory using a format known as IEEE 754, which defines how real numbers are represented in binary. The IEEE 754 standard specifies different formats, including single-precision (32-bit) and double-precision (64-bit). Let's use the single-precision format (32 bits) as an example:

A single-precision floating-point number consists of three parts:

1. Sign bit (1 bit): It represents the sign of the number (positive or negative).

2. Exponent (8 bits): This part stores the exponent value, which determines the scale of the number.

3. Significand (also known as mantissa) (23 bits): It stores the fraction part of the number.


Let's take an example to store the decimal number 7.25 in IEEE 754 single-precision format:

1. Convert 7.25 to binary:

7 (integer part) in binary is 111.

0.25 (fractional part) can be converted by multiplying it by 2: 0.25 * 2 = 0.5, which has a binary representation of 0.1.

Combine the two parts: 111.1

2. Normalize the binary representation: 

Shift the decimal point to have a single non-zero digit before the binary point, which gives us 1.111 * 2^2.

3. Determine the sign bit: The number is positive, so the sign bit is 0.

4. Determine the exponent: The exponent is 2, which needs to be biased to be stored in IEEE 754 format. The bias for single-precision is 127, so the actual exponent is 2 + 127 = 129, which is represented in binary as 10000001 (8 bits).

5. The significand is the fractional part of the normalized binary, which is 111.


Now, we combine these parts to store 7.25 in IEEE 754 single-precision format:

Sign bit: 0

Exponent: 10000001

Significand: 11100000000000000000000

So, in memory, the binary representation of 7.25 in IEEE 754 single-precision format would be:

0 10000001 11100000000000000000000


To retrieve the value from this binary representation, you would reverse the steps, including calculating the exponent and the fractional part based on the stored values and the bias.