Integer & Floating Point Representations CDA 3101 Discussion Session 05
Question 1 Converting into a 32-bit sign magnitude. Step 1: magnitude - converting 4047 to binary Step 2: Sign Inverting the MSB (sign bit)
Question 1 cont. Converting into a 32-bit 1 ’ s complement. Step 1: converting 4047 to binary Step 2: 1 ’ s complement: (unsigned)(X + x) = Inverting all the bits Check if (X+x) = ?
Question 1 cont. Converting into a 32-bit 2 ’ s complement. Step 1: converting 4047 to binary Step 2: 2 ’ s complement: (unsigned)(X + x) = Inverting all the bits (1 ’ s complement) Adding Check (X+x) = 2 n ?
Question 2 Converting the binary number to decimal, if the binary is Unsigned? 2 ’ s complement? Single precision floating-point?
Question 2.1 Converting bin (unsigned) to dec * * … + 1* * *2 2 =
Question 2.2 Converting bin (2 ’ s complement) to dec * * … + 1* * *2 2 =
Question 2.3 Converting bin (Single precision FP) to dec Sign bit : 1 Exponent : = 73 Fraction : =1* * … + 1* * *2 -21 = (-1) S * (1.Fraction) * 2 (Exponent - 127) = (-1) 1 * ( ) * 2 ( ) = * = * S(1)Biased Exponent(8)Fraction (23)
Question 3 Show the IEEE 754 binary representation for the floating-point number in single precision.
Question 3.1 Converting 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, … … … * 2 -4 Step2: Express in single precision format (-1) S * (1.Fraction) * 2 (Exponent +127) = (-1) 0 * ( ) * 2 (-4+127)
Overflow Example 4-bit signed ALU Signed Value Range [-8,7] The MSB is signed bit = 0111 –3+4 =7 –Positive + Positive = Positive = 1001 –4 +5 =-7 (the signed bit is 1) –Overflow
Overflow or Not? = = = =
Overflow or Not? = – (-3)+(-5) =(-8) = – (-7) + (-3) = 6 OVERFLOW! = – (-6) –(3) = 7 OVERFLOW! = – (4) –(-4) =( -8) OVERFLOW!
Any More Questions?