Presentation is loading. Please wait.

Presentation is loading. Please wait.

Integer & Floating Point Representations CDA 3101 Discussion Session 05.

Similar presentations


Presentation on theme: "Integer & Floating Point Representations CDA 3101 Discussion Session 05."— Presentation transcript:

1 Integer & Floating Point Representations CDA 3101 Discussion Session 05

2 Question 1 Converting -4047 10 into a 32-bit sign magnitude. Step 1: magnitude - converting 4047 to binary 0000 0000 0000 0000 0000 1111 1100 1111 2 Step 2: Sign Inverting the MSB (sign bit) 1000 0000 0000 0000 0000 1111 1100 1111 2

3 Question 1 cont. Converting -4047 10 into a 32-bit 1 ’ s complement. Step 1: converting 4047 to binary 0000 0000 0000 0000 0000 1111 1100 1111 2 Step 2: 1 ’ s complement: (unsigned)(X + x) = 2 32 - 1 Inverting all the bits 1111 1111 1111 1111 1111 0000 0011 0000 2 Check if (X+x) = 2 32 -1?

4 Question 1 cont. Converting -4047 10 into a 32-bit 2 ’ s complement. Step 1: converting 4047 to binary 0000 0000 0000 0000 0000 1111 1100 1111 2 Step 2: 2 ’ s complement: (unsigned)(X + x) = 2 32 1. Inverting all the bits (1 ’ s complement) 1111 1111 1111 1111 1111 0000 0011 0000 2 2. Adding 1 1111 1111 1111 1111 1111 0000 0011 0001 2 Check (X+x) = 2 n ?

5 Question 2 Converting the binary number 1010 0100 1001 0010 0100 1001 0010 0100 2 to decimal, if the binary is Unsigned? 2 ’ s complement? Single precision floating-point?

6 Question 2.1 Converting bin (unsigned) to dec 1010 0100 1001 0010 0100 1001 0010 0100 2 1*2 31 + 1*2 29 + … + 1*2 8 + 1*2 5 + 1*2 2 = 2761050404

7 Question 2.2 Converting bin (2 ’ s complement) to dec 1010 0100 1001 0010 0100 1001 0010 0100 2 -1*2 31 + 1*2 29 + … + 1*2 8 + 1*2 5 + 1*2 2 = -1533916892

8 Question 2.3 Converting bin (Single precision FP) to dec 1010 0100 1001 0010 0100 1001 0010 0100 2 Sign bit : 1 Exponent : 01001001 = 73 Fraction : 00100100100100100100100 =1*2 -3 + 1*2 -6 + … + 1*2 -15 + 1*2 -18 + 1*2 -21 =0.142857074 (-1) S * (1.Fraction) * 2 (Exponent - 127) = (-1) 1 * (1.142857074) * 2 (73 - 127) = -1.142857074 * 2 -54 = -6.344131187 * 10 -17 S(1)Biased Exponent(8)Fraction (23)

9 Question 3 Show the IEEE 754 binary representation for the floating-point number 0.1 10 in single ­ precision.

10 Question 3.1 Converting 0.1 10 to single-precision FP Step1: Covert fraction 0.1 to binary (multiplying by 2) 0.1*2 = 0.2, 0.2*2 = 0.4, 0.4*2 = 0.8, 0.8*2 = 1.6, 0.6*2 = 1.2, 0.2*2 = 0.4, 0.4*2 = 0.8, 0.8*2 = 1.6, 0.6*2 = 1.2, … 000110011 … 1.10011 … * 2 -4 Step2: Express in single precision format (-1) S * (1.Fraction) * 2 (Exponent +127) = (-1) 0 * (1.10011001100110011001100) * 2 (-4+127) 00111101110011001100110011001100

11 Overflow Example 4-bit signed ALU Signed Value Range [-8,7] The MSB is signed bit. 0011+ 0100 = 0111 –3+4 =7 –Positive + Positive = Positive 0100+0101 = 1001 –4 +5 =-7 (the signed bit is 1) –Overflow

12 Overflow or Not? 1101+1011 = 1001+1101 = 1010 -0011 = 0100 -1100 =

13 Overflow or Not? 1101+1011 = 1 1000 – (-3)+(-5) =(-8) 1001+1101 = 1 0110 – (-7) + (-3) = 6 OVERFLOW! 1010 -0011 = 0 0111 – (-6) –(3) = 7 OVERFLOW! 0100 -1100 = 1 1000 – (4) –(-4) =( -8) OVERFLOW!

14 Any More Questions?


Download ppt "Integer & Floating Point Representations CDA 3101 Discussion Session 05."

Similar presentations


Ads by Google