====================================================== Assignment #07 - Floating Point, Endian, Shifts, Characters, Booleans (*** REVISED DUE DATE ***) ====================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Monday February 28, 2011 Upload due date: *** REVISED DUE DATE *** Upload answer file before 23:59 (midnight) on Wednesday March 16, 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 "assignment07.txt" Upload the file via the Assignment07 "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. Some of the questions may 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, the same method you will have to use on tests and exams. ============================================================================== 0. What is the date, time, and room number of your Final Exam? *** Floating-Point Section *** 1. The IEEE 754 floating-point number 81234567h is negative. Without converting, give the hexadecimal for the same number, only positive. 2. IEEE 754 single-precision floating-point can store numbers in the approximate range of -2**127 to +2**127. Look up or use a calculator to express this range (approximately) as powers of ten (decimal). 3. How close to zero can you get with IEEE 754 32-bit floating point? (What is the non-zero value that is closest to zero?) Express the answer in both approximate power-of-two notation and in approximate power-of-ten notation. 4. What is floating-point underflow? (Reference: 02.ppt slide 81) 5. Give an example of a number that would cause floating-point underflow if you tried to calculate it or represent it using IEEE-754 single-precision floating-point. 6. Which has more *Precision* available - a 32-bit integer or a 32-bit floating-point number? (Reference: 02.ppt slides 82-83) 7. Which has more *Range* available, - a 32-bit integer or a 32-bit IEEE 754 floating-point number? (Reference: 02.ppt slides 82-83) 8. True/False: Decimal 1234.0 x 10**37 fits in IEEE 754 single precision floating point. 9. True/False: Decimal 0.00001 x 10**40 fits in IEEE 754 single precision floating point. 10. Without converting, mark with an "X" the sums that do not fit in IEEE 754 single-precision floating point with no loss of range or precision. Leave unmarked the values that do fit completely accurately: 2**30-3 2**30-1 2**30 2**30+1 2**30+3 2**30+2**29 11. Without converting, mark with an "X" the sums that do not fit in IEEE 754 single-precision floating point with no loss of range or precision. Leave unmarked the values that do fit completely accurately: 2**29+2**10+2**9+2**0 2**26+2**0 2**29+2**28+2**27+2**26 2**27+2**23+2**1 2**29+2**28+2**2+2**1 12. Why do the decimal numbers 2147483775 (0x8000007F) and 2147483648 (0x80000000) both convert to the same IEEE 754 single-precision floating-point number 0x4F000000 that has decimal value 2147483648.0? 13. Explain why, in a computer, floating point mathematics may not be associative or distributive, i.e. (A+B)+C may not equal A+(B+C). 14. Why must you never test floating-point numbers for equality, i.e. why is "if ( a == b )" a bad idea for floating point a and b? 15. What is the correct way to test for floating-point "equality"? (Reference: 02.ppt slides 72 and 84) 16. Write a tiny program fragment that uses a floating point loop that starts at 1.5, adds 0.1 each time through the loop, and stops when the loop counter is within 1.0e-5 ("epsilon") of the floating-point value 10.1. Give the code for the FOR loop here: (Reference: 02.ppt slides 72 and 84) 17. What is the likely final value of variable "z" in this IEEE 754 single-precision pseudo-code fragment: float x = 2**40 float y = x + 9 float z = x - y *** Endian Section *** 18. What byte-order is used on the Internet to transmit data? 19. What is the byte-order of AMD/Intel-based computers? *** Miscellaneous Section *** 20. If a memory has an access time of 50ns, how many accesses can you make in one second (give the answer in MHz)? 21. If a CPU has a clock frequency of 3.2 MHz, how long (in ns) does one access cycle take? 22. Why isn't a disk that rotates at 10,000 RPM exactly twice as fast as a disk that rotates at 5,000 RPM? What else is involved? 23. What are the smallest and largest decimal integers an 8-bit word can hold using an excess-127 (bias-127) representation? 24. In 13-bit two's complement representation, what decimal number do you get when you add one to decimal 4,095? 25. Convert the two's complement representation 12-bit hexadecimal number "EF6h" to decimal. 26. Why doesn't the number 1.5 * 10**50 fit accurately in an IEEE 754 single precision floating-point number? 27. Express -10 decimal in hexadecimal using 20-bit sign-magnitude notation. *** Bit Shifting Section *** 28. 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 29. 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 30. 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 31. 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 32. Is it still true that shifting a binary number left one bit multiplies it by two, if the number is a negative two's complement number? 33. What is the difference between an Arithmetic and Logical Right Shift? *** Character Section *** 34. True/False - In ASCII, you can add one to any letter to get the next letter in the alphabet (up to "Z"). 35. True/False - In UTF-8, you can add one to any English letter to get the next letter in the alphabet (up to "Z"). 36. Name and give the hex values of the seven "Famous ASCII Characters". 37. In ASCII, which comes first (i.e. has lower hex values): upper-case letters or lower-case letters? 38. If you sort a file containing lines of mixed-case ASCII text, what is the resulting relationship of lines that begin with upper-case letters and lines that begin with lower-case letters? (Which lines sort first in the file?) 39. If you sort a file containing lines of mixed-case ASCII text and numbers, what is the resulting relationship of lines starting with digits and lines starting with letters? (Which lines sort first in the file?) 40. If you want to give a Unix file an ASCII name that sorts before all other file names in a sorted directory listing, what non-blank character(s) might you use to begin the file name? 41. There is only one bit of difference between an upper-case ASCII character and its lower-case equivalent. What is the hexadecimal and decimal value of this difference? What ASCII character does this difference represent? 42. What hex values and (if printable) ASCII characters result from the following ASCII arithmetic (characters in single quotes are ASCII characters): EXAMPLE: 'A' + 1 = 41h + 1 = 42h = 'B' a) 'Z' - 2 = ? b) 'A' + ' ' = ? c) 'b' - 'B' = ? d) '9' - '1' = ? 43. How do the ASCII character set and the UTF-8 character set relate to each other? 44. How do the ASCII character set and the Unicode character set relate to each other? 45. True/False: Plain English text, encoded as ASCII, is identical to the same Plain English text encoded as UTF-8. 46. True/False: Plain English text, encoded as ASCII, is identical to the same Plain English text encoded as Latin-1. 47. True/False: Plain English text, encoded as ASCII, is identical to the same Plain English text encoded as Unicode. 48. What advantage does UTF-8 have over Unicode for English text? 49. Why can't a single text file contain both French, encoded as 8-bit Latin-1, and Polish, encoded as 8-bit Latin-2? 50. What is the default character set used in the Java language? 51. Without decoding using any ASCII table, explain why the following sequence of hexadecimal bytes is or is not likely to be from an ASCII text file: 84 03 fd ff ff c7 44 24 08 05 00 00 00 31 f6 c7 52. You look into memory and see the hexadecimal value 40h. Based on what you know in this course so far, what different things might this 40h represent? 53. Under what operating system was the following text file created? How do you know? 4C 69 6E 75 78 0D 0A 52 6F 63 6B 73 5C 21 0D 0A 54. Under what operating system was the following text file created? How do you know? 4C 69 6E 75 78 0D 52 6F 63 6B 73 5C 21 0D 55. Under what operating system was the following text file created? How do you know? 4C 69 6E 75 78 0A 52 6F 63 6B 73 5C 21 0A 56. Encode the following seven Famous ASCII characters in hexadecimal using 8-bit Even Parity: 1) A 2) a 3) '0' 4) CR 5) LF 6) SP 7) DEL 57. Encode the following seven Famous ASCII characters in hexadecimal using 8-bit Odd Parity: 1) A 2) a 3) '0' 4) CR 5) LF 6) SP 7) DEL 58. The following ASCII byte is received from a system that generates 8-bit Even Parity: 0xA7 Is there an error in the byte? How do you know? 59. The following ASCII byte is received from a system that generates 8-bit Odd Parity: 0xA5 Is there an error in the byte? How do you know? *** Boolean Section - see 03.ppt *** Recall that "NOT x" can be written in text using the "prime" mark: x' 60. True/False: (xy)' == x'y' In English: "NOT(red AND jello) == NOT red AND NOT jello" ? 61. True/False: (x + y)' == x' + y' In English: "NOT(red OR jello) == NOT red OR NOT jello" ? 62. Using deMorgan, write a simplified expression for the Boolean complement of the logic function F(a,b,c) = a(b' + c) "Complement" means apply Boolean "NOT". 63. Using deMorgan, write a simplified expression for the Boolean complement of the logic function F(a,b,c) = a + (b'c) 64. Show that x = xy + xy' using a Boolean truth table. 65. Prove that x = xy + xy' using a chain of simple Boolean Identities. 66. Construct a Boolean function F(a,b) that implements the XOR operator using only AND, OR, and NOT logic. (The truth table for the simple function should be the same as the XOR truth table.) 67. Write the simplest IF statement (simplify the Boolean logic) for the following programming problem specification: "Call the delete routine unless: the product_id is zero or the product_class is 'important'." 68. Write the simplest IF statement (simplify the Boolean logic) for the following programming problem specification: "A record is one where the modify_date date is less than a year old and the account_balance is bigger than zero. If the record is NOT current, call the delete routine." Full marks are awarded only if you show your method, the same method you will have to use on 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/