================================================= Assignment #03 - Number Systems ================================================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Tuesday January 26, 2010 Upload due date in the Blackboard Assignment Area: Upload "assignment03.txt" before 13:00 (1 pm) on Tuesday February 2, 2010 Do *not* use the DigitalDropbox to submit your answers. Answers will be posted shortly after the due date/time. Submission method: Upload via the "Assignments" CST8281_Assignment_03 upload. Use the file name given above. Upload only one single file of plain text, not HTML, not MSWord, not RTF. No fonts, no word-processing. Plain text only. Did I mention that the format is plain text (Notepad)? Due to bugs in Blackboard, you can only submit your Assignment to me *once*. After that, you cannot submit any more times. If you need to re-submit it, you have to email me to ask me to clear your previous submission. Do *not* use the DigitalDropbox to submit your answers. Answers will be posted after the due date/time so that you can check your answers before coming to labs and ask questions about the answers in the labs. Please check your answers (and my answers!). I go over each assignment in the lab if there are questions about the answers. No questions means no review - I'll presume you know the material. Questions similar to ones on these assignments will appear on your tests and exams. Not all assignments will be marked. See the Week 1 Notes for details. ============================================================================== Edit this file and answer the following questions. Upload the file containing the answers before the due date. Some of the answers below may require reading the URL links published in the weekly notes. The point of the conversions is not to show me the answer. I already give you many of the answers. The point is to show me that you have a clear *method* for getting that answer that works for you. You must show me a clear method that turns the decimal into binary, and vice-versa. The method must work for any unsigned decimal number (or fraction). Show me your method. The point of the conversions is not to show me that you can do the question backwards and convert the binary back to decimal by adding up powers of two in the answer. Your tests and exams won't have any answers. I asked you to convert the decimal to binary, not the other way around. A number in parentheses following a string of digits indicates the base of the preceding number, e.g. 365(10) 31(8) 011101010(2) Hexadecimal numbers are often written with a trailing 'h', e.g. FFh. C and Java prefix hex numbers with "0x", e.g. 0xFF, 0xDEADBEEF, and octal numbers with just a zero, e.g. 012, 015, 0777. When converting from binary to octal or hex digits, always start grouping binary bits from the right of the binary number. If you run out of bits for the last group of bits on the left, assume the leftmost missing bits are zero, e.g. when converting the five bits 11000(2) to octal, start grouping sets of three bits from the right and treat a left-over two bits 11(2) as three bits 011(2) (when converting to octal). When converting the five bits 11000(2) to hexadecimal, start grouping sets of four bits from the right and treat a left-over single bit 1(2) as four bits 0001(2) (when converting to hexadecimal). You will benefit from knowing the powers of two from 2**(-4) to 2**16. Of course you can work them out; however, having at least some of them memorized will make things go faster for you. You will also benefit from knowing the bit patterns for the sixteen hexadecimal digits from 0,...,9,A,...,F Of course you can work them out; however, having at least some of them memorized will make things go faster for you. Practice: Write down any three-digit decimal number (e.g. 314). Convert it to binary using your method. Check your work on the Internet, using a decimal-to-binary conversion web page. Google search: decimal to binary conversion Sample conversion site: http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html Quiz site: http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/binquiz.html Subtraction method (with pictures!): http://www.is.wayne.edu/olmt/binary/page3.htm You can check your work using any online converter; use Google to find one. e.g. http://www.tonymarston.net/php-mysql/converter.php 1. Write down all the powers of two from zero ("1") to 16 ("65,536"). 2. Write down all the negative powers of two from -1 ("0.5") to -4 ("0.0625"). 3. Convert 25(10) decimal to 11001(2) binary (see ECOA2e Chapter 2 slide 8). 4. Convert 147(10) decimal to 10010011(2) binary. 5. Convert 0.75(10) to 0.11(2) binary (see ECOA2e Chapter 2 slide 19). 6. Convert 0.8125(10) to 0.1101(2) binary (see ECOA2e Chapter 2 slide 21). 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.) 8. Write down the sixteen binary four-bit patterns for the hex digits 0,...,9,A,...,F along with their decimal (base-10) equivalents. 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) 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) 11. Convert the following binary to hexadecimal. Hint: Your answer will have eight hex digits, all different: 1011000010010111111001001110110(2) 12. Convert 6235(8) octal to C9D(16) hexadecimal. 13. What are the largest and smallest integers an 8-bit word can hold using an unsigned representation? 14. What are the largest and smallest integers a 16-bit word can hold using an unsigned representation? 15. Write 23(10) in octal and hexadecimal. 16. Show that Christmas == Halloween by converting DEC 25 to OCT 31 (DECimal/OCTal) 17. Write 11110110(2) in octal and hexadecimal. 18. Write 00010111(2) in octal and hexadecimal. 19. Write 11110111(2) in octal and hexadecimal. 20. Write 11101001(2) as octal and hexadecimal. 21. Write 10010011(2) as octal and hexadecimal. 22. Convert 8-bit 10010011(2) binary unsigned to 147(10) decimal. 23. Convert 16-bit 1A8C(16) to 6,796(10) decimal. 24. Convert 16-bit 7FFF(16) to 32,767(10) decimal. 25. Convert 16-bit unsigned 8000h to decimal 32,768. 26. Convert 16-bit unsigned A123h to decimal 41,251. 27. Convert 16-bit unsigned FFFFh to decimal 65,535 using a trick to make the manual labour easy. 28. Add 16-bit unsigned 8A9Ch to ABCDh and give the Result, Carry, and Overflow. Is the result correct? 29. Add 16-bit unsigned 9999h to 4321h and give the Result, Carry, and Overflow. Is the result correct? 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 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? 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 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 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 35. How many different numbers can be represented in 15 bits? 36. What is the largest unsigned positive number that can be represented in 15 bits? 37. What is the largest unsigned positive number that can be represented in one nybble? 38. There is no question number 38. Ignore this one. 39. Convert binary fraction 0.1111(2) to decimal. 40. Convert 8A9Ch and ABCDh to octal. -- | 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/