============================= Answers for Lab 03 (math lab) ============================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com 1. 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 2. 0.5 0.25 0.125 0.0625 3. 25 --> 11001 Subtraction method: take 1 x 16 from 25 leaving 9 <-- leftmost bit of answer is here take 1 x 8 from 9 leaving 1 take 0 x 4 from 1 leaving 1 take 0 x 2 from 1 leaving 1 take 1 x 1 from 1 leaving 0 <-- rightmost bit of answer is here OR: Division method: 25 div by 2 is 12 rem 1 <-- rightmost bit of answer 12 div by 2 is 6 rem 0 6 div by 2 is 3 rem 0 3 div by 2 is 1 rem 1 1 div by 2 is 0 rem 1 <-- leftmost bit of answer 4. 147 --> 10010011 Subtraction method: take 1 x 128 from 147 leaving 19 <-- leftmost bit of answer is here take 0 x 64 from 19 leaving 19 take 0 x 32 from 19 leaving 19 take 1 x 16 from 19 leaving 3 take 0 x 8 from 3 leaving 3 take 0 x 4 from 3 leaving 3 take 1 x 2 from 3 leaving 1 take 1 x 1 from 1 leaving 0 <-- rightmost bit of answer is here OR Division method: 147 div by 2 is 73 rem 1 <-- rightmost bit of answer 73 div by 2 is 36 rem 1 36 div by 2 is 18 rem 0 18 div by 2 is 9 rem 0 9 div by 2 is 4 rem 1 4 div by 2 is 2 rem 0 2 div by 2 is 1 rem 0 1 div by 2 is 0 rem 1 <-- leftmost bit of answer 5. 0.75 --> 0.11 Subtraction method: take 1 x 0.5 from 0.75 leaving 0.25 <-- leftmost bit of answer is here take 1 x 0.25 from 0.25 leaving 0 <-- rightmost bit of answer is here OR Multiplication method: 0.75 times 2 is 1 plus 0.5 <-- leftmost bit of answer is here 0.5 times 2 is 1 plus 0.0 <-- rightmost bit of answer is here 6. 0.8125 --> 0.1101 Subtraction method: take 1 x 0.5 from 0.8125 leaving 0.3125 <-- leftmost bit take 1 x 0.25 from 0.3125 leaving 0.0625 take 0 x 0.125 from 0.0625 leaving 0.0625 take 1 x 0.0625 from 0.0625 leaving 0.0 <-- rightmost bit OR Multiplication method: 0.8125 times 2 is 1 plus 0.625 <-- leftmost bit of answer is here 0.625 times 2 is 1 plus 0.25 0.25 times 2 is 0 plus 0.5 0.5 times 2 is 1 plus 0 <-- rightmost bit of answer is here 7. see ECOA2e Example 2.7 p.45 8. 0000 0001 0010 0011 ... 0111 1000 ... 1100 1101 1110 1111 0h 1h 2h 3h ... 7h 8h ... Ch Dh Eh Fh 0 1 2 3 ... 7 8 ... 12 13 14 15 9. 110 011 101 010 100 001 111 000 6 3 5 2 4 1 7 0 octal (group from right by 3 bits) 10. 1110 1101 0011 1001 1100 0000 0001 1010 E D 3 9 C 0 1 A hex (group from right by 4 bits) 11. 0101 1000 0100 1011 1111 0010 0111 0110 5 8 4 B F 2 7 6 hex (group from right by 4 bits) 12. Convert 6235 octal to C9D hexadecimal (ECOA2e Example 2.9 p.46). 6235 = 110 010 011 101 = 1100 1001 1101 = C9Dh 13. What are the largest and smallest integers an 8-bit word can hold using an unsigned representation? + 2**8 - 1 = +255 (+0 -> +255) + 0 = 0 14. What are the largest and smallest integers an 8-bit word can hold using a sign-magnitude representation? (p.47) Half the of the 2**8 bit patterns are negative; half are positive. 2**8 divided by two is 2**7. We start from zero, therefore: + 2**7 - 1 = +127 (+0 -> +127) - 2**7 - 1 = -127 (-0 -> -127) 15. What are the largest and smallest integers an 8-bit word can hold using a one's complement representation? + 2**7 - 1 = +127 (+0 -> +127) - 2**7 - 1 = -127 (-0 -> -127) 16. What are the largest and smallest integers an 8-bit word can hold using a two's complement representation? + 2**7 - 1 = +127 (+0 -> +127) - 2**7 = -128 (-1 -> -128 -- note how we start at -1 not -0) 17. 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 -- no negative numbers 18. What are the largest and smallest integers a 16-bit word can hold using a sign-magnitude representation? Half the of the 2**16 bit patterns are negative; half are positive. 2**16 divided by two is 2**15. We start from zero, therefore: + 2**15 - 1 = +32,767 (+0 -> +32,767) - 2**15 - 1 = -32,767 (-0 -> -32,767) 19. 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) 20. hat are the largest and smallest integers a 16-bit word can hold using a two's complement representation? + 2**15 - 1 = +32,767 (+0 -> +32,767) - 2**15 = -32,768 (-1 -> -32,768 -- note how we start at -1 not -0) 21. Convert 23 to 8-bit 00010111 binary one's complement (ECOA2e Example 2.16 p.53). 22. Write 23 decimal in octal and hexadecimal. 23 decimal = 23 decimal = 2 * 10**1 + 3 * 10**0 23 decimal -> 2 tens and 3 ones 23 decimal = 27 octal = 2 * 8**1 + 7 * 8**0 27 octal -> 2 eights and 7 ones 23 decimal = 17 hexadecimal = 1 * 16**1 + 7 * 16**0 17 hexadecimal -> 1 sixteen and 7 ones 23. Convert -9 to 8-bit 11110110 binary one's complement (ECOA2e Example 2.16 p.53). 24. Write 11110110 in octal and hexadecimal. 11110110 = 011 110 110 = 366 octal 11110110 = 1111 0110 = F6 hexadecimal 25. Convert -23 to 8-bit 11101000 binary one's complement. 23 decimal = 16+4+2+1 = 00010111 complement -> 11101000 26. How do you know that a two's-complement addition has overflowed? positive+positive=negative -OR- negative+negative=positive 27. Convert 23 to 8-bit 00010111 binary two's complement (ECOA2e Example 2.19 p.54). 28. Write 00010111 in octal and hexadecimal. 00010111 = 000 010 111 = 27 octal 00010111 = 0001 0111 = 17 hexadecimal 29. Convert -9 to 8-bit 11110111 binary two's complement (ECOA2e Example 2.19 p.54). 30. Write 11110111 in octal and hexadecimal. 11110111 = 011 110 111 = 367 octal 11110111 = 1111 0111 = F7 hexadecimal 31. Convert -23 to 8-bit 11101001 binary two's complement (ECOA2e Example 2.19 p.54). 32. Write 11101001 as octal and hexadecimal. 11101001 = 011 101 001 = 351 octal 11101001 = 1110 1001 = E9 hexadecimal 33. Write 10010011 as octal and hexadecimal. 10010011 = 010 010 011 = 223 octal 10010011 = 1001 0011 = 93 hexadecimal 34. Convert 8-bit 10010011 binary unsigned to 147 decimal. 128+16+2+1 = 147 decimal 35. Convert 8-bit 10010011 binary sign-magnitude to -19 decimal (note the negative). [remove sign bit] 0010011 = 16+2+1 = 19 -> [add sign] -19 36. Convert 8-bit 10010011 binary one's complement to -108 decimal (note the negative). 10010011 -> [flip bits] 01101100 = 64+32+8+4 = 108 -> [add sign] -108 37. Convert 8-bit 10010011 binary two's complement to -109 decimal (note the negative). 10010011 -> [flip bits] 01101100 -> [add one] 01101101 = 109 -> [add sign] -109 38. Copy the left column of ECOA2e Table 2.2 p.63 and perform the given two's complement additions. Without looking, fill in the remaining four columns based on the results. Add another column that states whether the result is correct if treated as unsigned math instead of two's complement. Added column: The unsigned result is correct iff the carry flag is off. 39. Convert 16-bit two's complement 1A8Ch to 6,796 decimal. 1 * 16**3 + 10 * 16**2 + 8 * 16**1 + 12 * 16**0 = 4096 + 2560 + 128 + 12 = 6,796 40. Convert 16-bit two's complement 7FFFh to 32,767 decimal. 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 41. Convert 16-bit two's complement 8000h to decimal -32,768 (note the negative). 8000h -> [flip bits] 7FFFh -> [add one] 8000h = 32,768 -> [add sign] -32,768 42. Convert 16-bit two's complement A123h to decimal -24,285 (note the negative). A123h -> [flip bits] 5EDCh -> [add one] 5EDDh = 24,285 -> [add sign] -24,285 43. Convert 16-bit two's complement FFFF to decimal -1 (note the negative). FFFFh -> [flip bits] 0000h -> [add one] 0001h = 1 -> [add sign] -1 -OR- note that FFFFh + 1 = 0000h (zero), therefore FFFFh = 0 - 1 = -1 44. Circle the negative numbers (16-bit two's complement): 8000h 8001h 9FC5h A123h BFFFh 45. Add 16-bit two's complement ABCDh to 7FFFh and give the Result, Carry, and Overflow. Is the result correct? ABCDh + 7FFFh = 2BCCh [carry on] [no overflow possible] [correct] 46. Add 16-bit two's complement 8A9Ch to ABCDh and give the Result, Carry, and Overflow. Is the result correct? 8A9Ch + ABCDh = 3669h [carry on] [overflow on] [wrong answer] 47. Add 16-bit two's complement 9999h to 4321h and give the Result, Carry, and Overflow. Is the result correct? 9999h + 4321h = DCBAh [no carry] [no overflow possible] [correct]