============================================ Notes and answers for Lab 05 (computer math) ============================================ - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Text References: ECOA2e Section 2.3, 2.4, 2.5 Class Notes http://teaching.idallen.com/cst8214/07f/ binary_math.txt Binary Mathematics, unsigned, two's complement, etc. hexadecimal_conversions.txt Converting to/from hexadecimal (base 16) overflow.txt Calculating the OVERFLOW flag in binary arithmetic ieee754_conversions.txt Converting to/from IEEE 754 floating point format You can check your work using any online converter; use Google to find one. e.g. http://www.tonymarston.net/php-mysql/converter.php http://www.h-schmidt.net/FloatApplet/IEEE754.html A quiz is here: http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/binquiz.html Base 36: http://www.cut-the-knot.org/recurrence/word_primes.shtml Many bases: http://www.cut-the-knot.org/binary.shtml 1.What are the largest and smallest integers a 16-bit word can hold using a sign-magnitude representation? + 2**15 - 1 = +32,767 (+0 -> +32,767) - 2**15 - 1 = -32,767 (-0 -> -32,767) 2.What are the largest and smallest integers a 16-bit word can hold using a one's complement representation? + 2**15 - 1 = +32,767 (+0 -> +32,767) - 2**15 - 1 = -32,767 (-0 -> -32,767) 3.What are the largest and smallest integers a 16-bit word can hold using an unsigned representation? + 2**16 - 1 = +65,535 (+0 -> +65,535) + 0 = 0 4.Convert 16-bit unsigned 1A8Ch to decimal 6,796 and compare with the two's complement conversion. 1 * 16**3 + 10 * 16**2 + 8 * 16**1 + 12 * 16**0 = 4096 + 2560 + 128 + 12 = 6,796 same as two's complement (because it's positive) 5.Convert 16-bit unsigned 7FFFh to decimal 32,767 and compare with the two's complement conversion. Hard way: 7 * 16**3 + 15 * 16**2 + 15 * 16**1 + 15 * 16**0 = 28672 + 3840 + 240 + 15 = 32,767 Easy way: 07FFFh + 1 = 08000h = 2**15 (or 8 * 16**3) = 32,768 therefore 07FFFh = 32,768 - 1 = 32,767 same as two's complement (because 7FFFh is a positive number) 6.Convert 16-bit unsigned 8000h to decimal 32,768 and compare with the two's complement conversion. 8000h = 2**15 (or 8 * 16**3) = 32,768 in two's complement 8000h is a (very) negative number: -32,768 7.Convert 16-bit unsigned A123h to decimal 41,251 and compare with the two's complement conversion. 10 * 16**3 + 1 * 16**2 + 2 * 16**1 + 3 * 16**0 = 40960 + 256 + 32 + 3 = 41,251 in two's complement A123h is a negative number: -24,285 8.Convert 16-bit unsigned FFFFh to decimal 65,535 and compare with the two's complement conversion. Hard way: 15 * 16**3 + 15 * 16**2 + 15 * 16**1 + 15 * 16**0 = 61440 + 3840 + 240 + 15 = 65,535 Easy way: 0FFFFh + 1 = 10000h = 2**16 (or 1 * 16**4) = 65,536 therefore 0FFFFh = 65,536 - 1 = 65,535 9.Circle the negative numbers (16-bit unsigned): none 10.Add 16-bit unsigned ABCDh to 7FFFh and give the Result, Carry, and Overflow. Is the result correct? ABCDh + 7FFFh = 2BCCh [carry on] [no overflow possible] [wrong answer] 11.Add 16-bit unsigned 8A9Ch to ABCDh and give the Result, Carry, and Overflow. Is the result correct? 8A9Ch + ABCDh = 3669h [carry on] [overflow on] [wrong answer] 12.Add 16-bit unsigned 9999h to 4321h and give the Result, Carry, and Overflow. Is the result correct? 9999h + 4321h = DCBAh [no carry] [no overflow possible] [correct] 13.Convert decimal 147.625 to IEEE 754 single-precision format 4313A000h See Class Notes ieee754_conversions.txt 14.Convert decimal 2004 to IEEE 754 single-precision format 44FA8000h See Class Notes ieee754_conversions.txt 15.Convert decimal -20.5 to IEEE 754 single-precision format C1A40000h See Class Notes ieee754_conversions.txt 16.Convert decimal -0.5 to IEEE 754 single-precision format BF000000h See Class Notes ieee754_conversions.txt 17.Convert decimal -1 to IEEE 754 single-precision format BF800000h See Class Notes ieee754_conversions.txt 18.Convert IEEE 754 single-precision format 438F0000h to decimal 286 See Class Notes ieee754_conversions.txt 19.Convert IEEE 754 single-precision format BF880000h to decimal -1.0625 See Class Notes ieee754_conversions.txt 20.The IEEE 754 floating-point number 81234567h is negative. Without converting, give the hexadecimal for the same number, only positive. 81234567h -> 01234567h 21.The IEEE 754 floating-point number 7EDCBA98h is positive. Without converting, give the hexadecimal for the same number, only negative. 7EDCBA98h -> FEDCBA98h 22.Without converting, circle all the IEEE 754 negative numbers: 87B5CDE2h 90A5B5EFh A0000037h D1B8765Ah F0000000h