=========================================== Assignment #03 - Data Representations =========================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Thursday January 20, 2011 Upload due date: Upload answer file before 23:59 (midnight) on Thursday January 27, 2011 Answers will be posted shortly after the due date/time and discussed in class, if there are any questions about the answers. Late assignments may or may not be marked. Submission method: Create a plain text file using the exact name "assignment03.txt" Upload the file via the Assignment03 "Upload File" facility in Blackboard. Use "Attach File" and "Submit" to upload your plain text file. No wordprocessor documents. Do not send email. Use only "Attach File". Use the file name given above. Upload only one single file of plain text, not HTML, not MSWord. No fonts, no word-processing. Plain text only. Did I mention that the format is plain text (VIM/Nano/Pico/Gedit or Notepad)? NO WORD PROCESSOR DOCUMENTS ACCEPTED. No marks are awarded for submitting under the wrong assignment number. Not all assignments will be marked. See the Week 1 Notes for details. Answers will be posted after the due date/time so that you can check your answers before coming to class and ask questions about the answers in class. Please check your answers (and my answers!). I go over each assignment in class 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. DO THIS: Edit this file and answer the following questions underneath each question, showing the method or formula you used to get the answer. Many of the questions already give you the answer - you must show the full method you use to generate that answer. Upload the file containing the question, methods, formulas, and answers before the due date. Some of the answers below will require reading the links published in the weekly course notes. Full marks are awarded only if you show your method. ============================================================================== 1. Write down all the powers of two from zero ("1") to 16 ("65,536") showing their decimal values. Memorizing these powers of two will serve you well in Computer Science: 2. Write down all the negative powers of two from -1 ("0.5") to -4 ("0.0625") showing their decimal and fractional (reciprocal) values: 3. Write down all the powers of 16 from zero ("1") to 4 ("65,536") and relate each power of 16 to the corresponding power of two. 4. Using a word size of four bits, list in order vertically all of the possible bit patterns from 0000(2) to 1111(2). Beside each of the 16 patterns, give: a) the hexadecimal equivalent of the bit pattern b) the unsigned decimal value of the bit pattern c) the four-bit signed-magnitude decimal value of the bit pattern d) the four-bit one's complement decimal value of the bit pattern e) the four-bit two's complement decimal value of the bit pattern You will create a small text table with 16 rows and five columns. Class Notes Reference: 060_different_binary_integers.html 5. Why do computer programmers always start counting with zero (0), and not with one (1)? 6. The prefix used for a thousand Kilobytes is Megabytes. What is the prefix used for a thousand Gigabytes? 7. The prefix used for a thousand Kilobytes is Megabytes. What is the prefix used for a thousand Terabytes? 8. What is the difference between writing KB (kilobyte) and KiB (kibibyte) and MB (megabyte) and MiB (mebibyte)? 9. What is the closest power of two to 1000 (i.e. closest to 10**3)? 10. How many ns (nanoseconds) are in a ms (millisecond)? 11. How many KiB are in a GiB? 12. How many MiB are in a GiB? Give the answer as a power of two. 13. Which of these measurements are powers of two, and which are powers of ten? a) Distances in kilometres? b) amount of hard disk capacity? c) amount of CDROM capacity? d) computer memory size? e) processor speed (clock frequency)? f) processor bus speed (e.g. PCI bus or front side bus or memory bus)? g) network card speed? h) dial-up modem speed? i) ADSL modem speed? j) Size of a file on your hard disk? 14. Give two reasons why you can't store 8GB of system memory in a file on a hard drive with an advertised capacity of 8GB. 15. What is 2**16 in decimal? 16. A computer has a 32-bit word size. Using this word size, what is the largest size memory it can address, in GiBi? (Microsoft Windows XP computers are limited to using this much memory.) 17. By what order of magnitude (power of 10) is something that runs in nanoseconds (e.g. a CPU memory access) faster than something that runs in milliseconds (e.g. a hard disk access)? 18. Refer to the above answer. You have a program that takes 8 minutes to finish, running entirely in the computer's memory. With a bigger data set, you need to change the program to access the hard disk instead of memory. You change the program so that *all* accesses are via the slower hard disk. Roughly how long (in years) will it now take your "8-minute" program to finish? 19. Exactly how many bytes (in decimal) are in 4GiB of memory? 20. Exactly how many bytes (in decimal) are on an advertised 4GB hard disk? 21. How many power-of-two TiB are on an advertised 1.5TB hard disk? 22. By what percentage is a power-of-two GiB larger than a power-of-ten GB? 23. By what percentage is a power-of-two TiB larger than a power-of-ten TB? 24. Which has more space, a 2 TB disk or a 1.8 TiB disk? 25. How many power-of-two MiB are on an advertised 2TB hard disk? How many power-of-two GiB are on an advertised 2TB hard disk? How many power-of-two TiB are on an advertised 2TB hard disk? 26. What are the largest and smallest integers (in decimal) an 8-bit word can hold using a sign-magnitude representation? 27. What are the largest and smallest integers (in decimal) an 8-bit word can hold using a one's complement representation? 28. What are the largest and smallest integers (in decimal) an 8-bit word can hold using a two's complement representation? 29. What are the largest and smallest integers a 16-bit word can hold using a sign-magnitude representation? 30. What are the largest and smallest integers a 16-bit word can hold using a one's complement representation? 31. What are the largest and smallest integers a 16-bit word can hold using a two's complement representation? 32. Generalize: For an N-bit word size, express as a formula using N as a power of two (i.e. using 2**N) what are the largest (most positive) and smallest (least positive) integers possible for: a) N-bit unsigned b) N-bit one's complement c) N-bit signed-magnitude d) N-bit two's complement Your formulas should produce the answers you gave in the above questions, e.g. your formula should output "+1023" for N=10 unsigned. 33. What is the minimum number of binary bits needed to represent 187 items? Knowing your powers-of-two table makes this a quick answer. 34. What is the minimum number of binary bits needed to represent 31,386 items? Knowing your powers-of-two table makes this a quick answer. 35. What is the minimum number of binary bits needed to represent the number of days in a week? 36. What is the minimum number of binary bits needed to represent the number of each day in the year, if the number of days in the year can be used positive or negative (e.g. "minus 300 days" or "today - 300")? Knowing your powers-of-two table makes this a quick answer. 37. Develop a binary encoding scheme which could be used to encode a field to represent one of the weeks of the year. Use the minimum number of bits. Knowing your powers-of-two table makes this a quick answer. 38. How many different numbers can be represented in 15 bits? 39. What is the largest unsigned positive number that can be represented in 15 bits? 40. What is the largest unsigned positive number that can be represented in one nybble? 41. Unix/Linux has traditionally used a 32-bit signed integer to store the number of seconds since midnight on January 1, 1970, UTC. Calculate roughly in what year/month/day this value overflows and time starts going negative. (Modern Unix systems use 64 bit time.) 42. Convert the following binary to hexadecimal. Hint: Your answer will have eight hex digits, all different: 1011000010010110010111101110110(2) 43. Express floating-point 123.654 as a normalized decimal number using scientific notation with four significant digits of precision. 44. Add floating-point decimal 1243000.0 to 1.6 and express the result as a normalized decimal number using scientific notation with four significant digits of precision. 45. Add *binary* floating-point 1101000.0 to 1.11 and express the result as a normalized binary number using (binary) scientific notation with four (binary) significant digits of precision. 46. Looking at the two previous questions, is it possible in a computer to add a small floating-point number to a larger floating-point number without having any effect, i.e. is it true that A+B=A for certain floating-point values where B is much smaller than A? Class Notes Reference: 090_FloatingPoint.htm 47. Assuming unsigned binary encoding, what decimal value is represented by the binary pattern: 1 0 1 0 1 0 0 1 ? 48. Conversions from different bases and representations to decimal: a) Given the digits 101011(16), convert to decimal from base "16" = b) Given the digits 101011(10), convert to decimal from base "10" = c) Given the digits 101011(8), convert to decimal from base "8" = d) Given the digits 101011(2), convert to decimal from base "2" = e) Given the digits 101011(-2), convert to decimal from base "-2" = f) Given the digits 101011(2), convert to decimal from bias-127 = g) Given the digits 101011(2), convert to decimal from bias-63 = h) Given the digits 101011(2), convert to decimal from bias-31 = i) Given the digits 101011(2), convert to decimal from bias-16 = Reference: http://en.wikipedia.org/wiki/Signed_number_representations Class Notes Reference: 060_different_binary_integers.html 49. In a 16-bit word, unsigned, what is the decimal value of the top bit? (What is the decimal value of an unsigned binary 16-bit number that has only the highest bit set?) 50. True/False: The most negative two's complement number has only the sign bit turned on and all the other bits are zeroes. 51. True/False: Two's complement -1 is always "all bits on". 52. What happens mathematically 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? DO THIS: Edit this file and answer the above questions underneath each question, showing the method or formula you used to get the answer. Many of the questions already give you the answer - you must show the full method you use to generate that answer. Upload the file containing the question, methods, formulas, and answers before the due date. Some of the answers above will require reading the links published in the weekly course notes. Full marks are awarded only if you show your method. Answers will be posted after the due date/time so that you can check your answers before coming to class and ask questions about the answers in class. Please check your answers (and my answers!). I go over each assignment in class 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. -- | 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/