0% found this document useful (0 votes)
10 views3 pages

CS302

CS 302 Assignment no 1 2024 solution

Uploaded by

Bilal Mustafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

CS302

CS 302 Assignment no 1 2024 solution

Uploaded by

Bilal Mustafa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 302 Assignment NO 1 Solution

Name: Bilal Mustafa


ID: BC220402092

Question # 01 Solution:
11000100110110101011010111000111

32-bit floating-point number is represented as follows:


1 bit for the sign (S)
8 bits for the exponent (E)
23 bits for the mantissa (fraction) (M)

Separate the parts:


Sign bit (S) = 1
Exponent (E) = 10001001
Mantissa (M) = 10110101011010111000111

The sign bit determines if the number is positive or negative:


 If the sign bit is 0, the number is positive.
 If the sign bit is 1, the number is negative.
Here, the sign bit is 1, so the number will be negative.

Convert the Exponent to Decimal and Find the Actual Exponent:


10010012
1 * 27 + 0 * 26 + 0 * 25 + 0 * 24 + 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20
128 + 0 + 0 + 0 + 8 + 0 + 0 + 1
137
100010012 = 13710
Calculate the unbiased exponent: IEEE 754 format uses a bias of 127 for 32-bit floating point
numbers. So, subtract 127 from the exponent we just calculated:
137 – 127 = 10
The actual exponent is 10

Normalize the Mantissa and Convert to Decimal:


10110101011010111000111
In IEEE 754 format, the mantissa (or fraction) is assumed to have an implicit leading 1 in
normalized form. So, we can write the mantissa as:
1.10110101011010111000111
Convert 1.10110101011010111000111 to decimal
The integer part is 1
For the fractional part 10110101011010111000111, we interpret each binary digit after the
decimal point as a negative power of 2:
1 * 2-1 + 0 * 2-2 + 1 * 2-3 + 1 * 2-4 + 0 * 2-5 + 1 * 2-6 + 0 * 2-7 + 1 * 2-8 + 0 * 2-9 + 1 * 2-10 + 1 * 2-11 + 0
* 2-12 + 1 * 2-13 + 0 * 2-14 + 1 * 2-15 + 1 * 2-16 + 1 * 2-17 + 0 * 2-18 + 0 * 2-19 + 0 * 2-20 + 1 * 2-21 + 1 * 2-22
+ 1 * 2-23
0.5 + 0 + 0.125 + 0.0625 + 0 + 0.0156 + 0 + 0.0039 + 0 + 0.0009 + 0.0004 + 0 + 0.0001 + 0 +
0.00003 + 0.00001 + 0.000007 + 0 + 0 + 0 + 0 + 0 + 0
0.7109375
So the mantissa in decimal is:
Integer Part + Fractional Part
1+ 0.7109375
1.7109375

Apply the Exponent:


1.7109375 * 210 = 1.7109375 * 1024 ≈ 1751.5
Apply the Sign:
Since the sign bit was 1, the final value is negative:
-1751.5
So, the final Answer is:
11000100110110101011010111000111
-1751.5

You might also like