================================================= Assignment #03 - Number Systems ================================================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Sources for these answers (thank you!): - Rabih Yassine - Ian Allen - Randelle Ashley 1. Write down all the powers of two from zero ("1") to 16 ("65,536"). 1 = 2**0 2 = 2**1 4 = 2**2 8 = 2**3 16 = 2**4 32 = 2**5 64 = 2**6 128 = 2**7 256 = 2**8 512 = 2**9 1024 = 2**10 2048 = 2**11 4096 = 2**12 8192 = 2**13 16384 = 2**14 32768 = 2**15 65536 = 2**16 2. Write down all the negative powers of two from -1 ("0.5") to -4 ("0.0625"). 0.5 = 2**-1 0.25 = 2**-2 0.125 = 2**-3 0.0625 = 2**-4 3. Convert 25(10) decimal to 11001(2) binary (see ECOA2e Chapter 2 slide 8). 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. Convert 147(10) decimal to 10010011(2) binary. 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. Convert 0.75(10) to 0.11(2) binary (see ECOA2e Chapter 2 slide 19). 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. Convert 0.8125(10) to 0.1101(2) binary (see ECOA2e Chapter 2 slide 21). 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. Convert 0.34375(10) to 0.0101(2) binary, stopping at four fractional bits. (This does not mean truncating 0.34375 to 0.3437. It means calculating the binary fraction for 0.34375 and stopping when you have four binary digits to the right of the binary radix point, as shown in the answer above. The remaining bits are left uncalculated, and so the answer is actually wrong - it doesn't add up. Computers are like that - sometimes you don't have space for all the binary bits and the answer is wrong.) 0.34375 -0.00000 = 2**-1 x 0 <-- leftmost bit -------- 0.34375 -0.25000 = 2**-2 x 1 -------- 0.09375 -0.00000 = 2**-3 x 0 -------- 0.09375 -0.06250 = 2**-4 x 1 <-- rightmost bit - stop at 4 bits -------- 0.03125 8. Write down the sixteen binary four-bit patterns for the hex digits 0,...,9,A,...,F along with their decimal (base-10) equivalents. 0 = 0000 = 0 1 = 0001 = 1 2 = 0010 = 2 3 = 0011 = 3 4 = 0100 = 4 5 = 0101 = 5 6 = 0110 = 6 7 = 0111 = 7 8 = 1000 = 8 9 = 1001 = 9 10 = 1010 = A 11 = 1011 = B 12 = 1100 = C 13 = 1101 = D 14 = 1110 = E 15 = 1111 = F 9. Convert the following binary value to octal (base 8) by using groups of three bits, starting from the right. Hint: Your answer will have eight octal digits and the rightmost octal digit will be "0": 110011101010100001111000(2) 0 = 000 1 = 001 2 = 010 3 = 011 110 011 101 010 100 001 111 000 (group from right) 4 = 100 6 3 5 2 4 1 7 0 5 = 101 6 = 110 7 = 111 = 63524170(8) 10. Convert the following binary to hexadecimal (base 16) by using groups of four bits, starting from the right. Hint: Your answer will have eight hex digits and the rightmost hex digit will be "A": 11101101001110011100000000011010(2) 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 1110 1101 0011 1001 1100 0000 0001 1010 (from right) 6 = 0110 E D 3 9 C 0 1 A 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1111 = ED39C01A(16) 11. Convert the following binary to hexadecimal. Hint: Your answer will have eight hex digits, all different: 1011000010010111111001001110110(2) 1011000010010111111001001110110(2) = 0101 1000 0100 1011 1111 0010 0111 0110 (group binary from right) 5 8 4 B F 2 7 6 (hex) = 584BF276(16) 12. Convert 6235(8) octal to C9D(16) hexadecimal. 6235(8) = 110 010 011 101(2) = 1100 1001 1101(2) = C9Dh 6 2 3 5 C 9 D 13. What are the largest and smallest integers an 8-bit word can hold using an unsigned representation? smallest = 0 largest = 255 [ = (2**8)-1 ] 14. What are the largest and smallest integers a 16-bit word can hold using an unsigned representation? smallest = 0 largest = 65535 [ = (2**16)-1 ] 15. Write 23(10) in octal and hexadecimal. 23 -16 = 2 x 8**1 --- 7 - 7 = 7 x 8**0 --- 0 = 27(8) 23 -16 = 1 x 16**1 --- 7 - 7 = 7 x 16**0 --- 0 = 17(16) 16. Show that Christmas == Halloween by converting DEC 25 to OCT 31 (DECimal/OCTal) 25(10) -24 = 3 x 8**1 --- 1 - 1 = 1 x 8**0 --- 0 = 31(8) 17. Write 11110110(2) in octal and hexadecimal. 11110110(2) = 011 110 110 (group by three bits from right) 3 6 6 = 366(8) = 1111 0110 (group by four bits from right) F 6 = F6(16) 18. Write 00010111(2) in octal and hexadecimal. 00010111(2) = 000 010 111 0 2 7 = 027(8) = 0001 0111 1 7 = 17(16) 19. Write 11110111(2) in octal and hexadecimal. 11110111(2) = 011 110 111 (group by three bits from right) 3 6 7 = 367(8) = 1111 0111 (group by four bits from right) F 7 = F7(16) 20. Write 11101001(2) as octal and hexadecimal. 11101001(2) = 011 101 001 (group by three bits from right) 3 5 1 = 351(8) = 1110 1001 (group by four bits from right) E 9 = E9(16) 21. Write 10010011(2) as octal and hexadecimal. 10010011(2) = 010 010 011 (group by three bits from right) 2 2 3 = 223(8) = 1001 0011 (group by four bits from right) 9 3 = 93(16) 22. Convert 8-bit 10010011(2) binary unsigned to 147(10) decimal. 10010011(2) = 1 x 2**0 + 1 x 2**1 + 0 x 2**2 + 0 x 2**3 + 1 x 2**4 + 0 x 2**5 + 0 x 2**6 + 1 x 2**7 = 147(10) Or 10010011(2) = 1001 0011(2) = 93(16) = 9*16 + 3 = 147 23. Convert 16-bit 1A8C(16) to 6,796(10) decimal. 1A8C(16) = 12 X 16**0 + 8 X 16**1 + 10 X 16**2 + 1 X 16**3 = 6796(10) 24. Convert 16-bit 7FFF(16) to 32,767(10) decimal. 7FFF(16) = 15 X 16**0 + 15 X 16**1 + 15 X 16**2 + 7 X 16**3 = 32767(10) Or note that 7FFF(16) + 1 = 8000(16) = 8 * 16**4 = 8 * 4096 = 32,768 so the answer must be one less: 32,767 25. Convert 16-bit unsigned 8000h to decimal 32,768. 8000(16) = 8 x 16**3 + 0 x 16**2 + 0 x 16**1 + 0 x 16**0 = 8 x 4096 = 32768 26. Convert 16-bit unsigned A123h to decimal 41,251. A123(16) = 3 X 16**0 + 2 X 16**1 + 1 X 16**2 + 10 X 16**3 = 41251(10) 27. Convert 16-bit unsigned FFFFh to decimal 65,535 using a trick to make the manual labour easy. FFFF(16) is hard. FFFF + 1 = 10000(16) is easy, and is one bigger than FFFF(16). 10000(16) = 1 x 16**4 = 1 * 65,536 = 65,536 so our answer FFFF(16) must be: 65,535 28. Add 16-bit unsigned 8A9Ch to ABCDh and give the Result, Carry, and Overflow. Is the result correct? 1111 8A9Ch + ABCDh ------- 3669h Result = 3669h (must fit in 16 bits) Carry = 1 Overflow = 1 (negative plus negative cannot be positive) 29. Add 16-bit unsigned 9999h to 4321h and give the Result, Carry, and Overflow. Is the result correct? 9999h + 4321h ------- DCBAh Result = DCBAh Carry = 0 Overflow = 0 (overflow not possible if signs differ) 30. What happens mathematically to the value of a binary number if you "shift" the bits to the right one place by deleting the rightmost binary digit, e.g. 1100 --> 0110 The value is halved. Any fractional remainder is thrown away. 31. What happens to the range of values possible in a word if you increase the word length by one bit, e.g. from eight bits to nine bits or from 100 bits to 101 bits? The range of possible values doubles. 32. What happens to the value of a binary number if you "shift" the bits to the left two places by adding two zeros after the rightmost binary digit, e.g. 11001 --> 1100100 The value doubles twice, i.e. quadruples (multiply by four). 33. What happens to the value of an octal number if you "shift" the number to the left one place by adding one zero after the rightmost octal digit, e.g. 0377 --> 03770 The value is multiplied by 8 (the base). 34. What happens to the value of a hexadecimal number if you "shift" the number to the left one place by adding one zero after the rightmost hex digit, e.g. 0xABC --> 0xABC0 The value is multiplied by 16 (the base). 35. How many different numbers can be represented in 15 bits? 2**15 = 32,768 different numbers 36. What is the largest unsigned positive number that can be represented in 15 bits? 2**15 - 1 = 32,767 (because zero is one of the numbers) 37. What is the largest unsigned positive number that can be represented in one nybble? One nybble = half a byte = 4 bits 2**4 - 1 = 15(10) 38. There is no question number 38. Ignore this one. 39. Convert binary fraction 0.1111(2) to decimal. 0.1111(2) = 1 * 2**(-1) + 1 * 2**(-2) + 1 * 2**(-3) + 1 * 2**(-4) = 0.5 + 0.25 + 0.125 + 0.0625 = 0.9375 40. Convert 8A9Ch and ABCDh to octal. Convert 8A9C(16) to binary and re-group in 3-bit chunks for octal: 8 A 9 C(16) 1000 1010 1001 1100(2) 001 000 101 010 011 100(2) (always group from the right) 1 0 5 2 3 4(8) Convert ABCD(16) to binary and re-group in 3s: A B C D(16) 1010 1011 1100 1101(2) 001 010 101 111 001 101(2) (always group from the right) 1 2 5 7 1 5(8) -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/