================================================= Assignment #03 - Review of Fundamentals ================================================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Available online: Thursday September 30, 2010 Upload due date in the Blackboard Assignment Area: Upload "assignment03.txt" before 17:00 (5pm) on Wednesday October 6, 2010 Answers will be posted shortly after the due date/time and discussed in class, if there are any questions about the answers. Submission method: Upload via the "Assignments" assignment03 upload. 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 (e.g. using Notepad)? 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. Not all assignments will be marked. See the Week 1 Notes for details. ============================================================================== Edit this file and answer the following questions, showing the method or formula you used to get the answer. Upload the file containing the methods, formulas, questions and answers before the due date. Some of the answers below will require reading the links published in the weekly course notes. ============================================================================== 1. What is the date of your first midterm test? *** Numeric Section *** 2. 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 signed-magnitude c) N-bit one's complement d) N-bit two's complement Give two answers per data type: formulas for largest and smallest values 3. Conversions from different bases and representations to decimal: a) Given the digits 101010(16), convert to decimal from base "16" = b) Given the digits 101010(10), convert to decimal from base "10" = c) Given the digits 101010(8), convert to decimal from base "8" = d) Given the digits 101010(2), convert to decimal from base "2" = e) Given the digits 101010(-2), convert to decimal from base "-2" = f) Given the digits 101010(2), convert to decimal from bias-127 = g) Given the digits 101010(2), convert to decimal from bias-63 = h) Given the digits 101010(2), convert to decimal from bias-31 = i) Given the digits 101010(2), convert to decimal from bias-16 = Reference: http://en.wikipedia.org/wiki/Signed_number_representations 4. Perform the following additions and subtractions in binary, assuming a 6 bit word. Show the Result value plus the values of the Zero, Sign, Carry, and Overflow flag values for each (five answers for each). 010001 101101 + 101111 - 101101 011010 011010 - 001111 + 001111 5. If possible, convert the following decimal values into 2's complement form, assuming a 12-bit word. Show your 12-bit results in hexadecimal: a. -513 b. +513 c. -2 d. -2048 e. 2048 f. -2049 6. Perform the indicated arithmetic in hexadecimal, assuming a 12-bit word. Show the 12-bit hexadecimal result plus the ON/OFF states of the Zero, Sign, Carry and Overflow flags (five answers for each problem). D66 95A C38 ADF +29A -347 +88B -BCD Result: Zero: Sign: Carry: Ovflo: 7. 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. (Assume that a year is 365.25 days.) 8. Express floating-point 123.4567 as a normalized decimal number using scientific notation with five digits of precision. 9. Add floating-point decimal 4321000.0 to 3.9 and express the result as a normalized decimal number using scientific notation with five digits of precision. 10. Add *binary* floating-point 1011000.0 to 1.1 and express the result as a normalized binary number using (binary) scientific notation with five (binary) digits of precision. 11. 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=B for certain floating-point values where A is much smaller than B? 12. What is floating-point underflow? 13. 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. 14. Why must you never test floating-point numbers for equality, i.e. why is "if ( x == y )" a bad idea for floating point x and y? 15. What is the correct way to test for floating-point "equality"? 16. Write a tiny program fragment (any language, or pseudocode) that uses a floating point loop that starts at 1000.0, adds 0.1 each time through the loop, and stops when the loop counter is within 1.0e-7 ("epsilon") of the floating-point value 2000.0. Give the code for the loop here: *** Character Section *** 17. Find a hexadecimal table of ASCII characters and translate this string of hexadecimal bytes into ASCII characters: 50 65 6e 67 75 69 6e 73 20 41 72 65 20 46 52 45 45 0a 0d (For unprintable characters, give the ASCII names of the characters, e.g. 07h is the ASCII "BEL" character) 18. In ASCII, which comes first (i.e. has lower hex values): upper-case letters or lower-case letters? 19. 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 bit? What ASCII character does this bit value represent? 20. What values (in hexadecimal) result from the following ASCII arithmetic (characters in single quotes are ASCII chars; character ' ' is SPACE): a) 'B' + 1 = b) 'C' - 1 = c) 'D' + ' ' = d) 'q' - 'Q' = e) '8' - '0' = Now, express each of the above hex values as an ASCII printable character, if the hex value is printable. If not printable, look up the value in an ASCII table and give its ASCII character name (e.g. hex 07h is the "BEL" character that rings the terminal bell). 21. How do the ASCII character set and the Unicode character set relate to each other? 22. What is the default character set used in the Java language? 23. True/False: Plain English text, encoded as ASCII, is identical to the same Plain English text encoded as Latin-1. 24. True/False: French text, encoded as Latin-1, is identical to the same French text encoded as ASCII. (Trick question.) 25. True/False: Plain English text, encoded as ASCII, is identical to the same Plain English text encoded as Unicode. 26. If you sort a file containing lines of mixed-case ASCII text, what is the resulting order relationship of lines that begin with upper-case letters and lines that begin with lower-case letters? In other words - which lines sort first in the file? 27. Which file is smaller - Plain English text encoded as Latin-1 or Plain English text encoded as Unicode? 28. Why can't a single text file contain both French, encoded as 8-bit Latin-1, and Polish, encoded as 8-bit Latin-2? 29. 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: c4 05 fe fc d2 c7 34 24 08 05 00 00 00 31 f6 c7 *** Boolean Section *** Recall that "NOT x" can be written in text using the "prime" mark: x' 30. True/False: (ab)' == a'b' In English: "NOT(sweet AND sour) == NOT sweet AND NOT sour" ? 31. True/False: (a + b)' == a' + b' In English: "NOT(sweet OR sour) == NOT sweet OR NOT sour" ? 32. Using deMorgan, write a simplified expression for the Boolean complement of the logic function F(x,y,z) = x'(y + z') 33. Using deMorgan, write a simplified expression for the Boolean complement of the logic function F(x,y,z) = x' + (yz') 34. Show that a = ab' + ab using a Boolean truth table. 35. Prove that a = ab' + ab using a chain of simple Boolean Identities. 36. Construct a Boolean function F(x,y) that implements the XOR operator using only AND, OR, and NOT logic. (The truth table for the simple Boolean function should be the same as the XOR truth table.) 37. Write the simplest IF statement (simplify the Boolean logic) for the following programming problem specification: "Call the ADD routine unless: the COST is not zero or the STATUS is not 'broken'." Note that "unless" means "IF NOT TRUE THAT". 38. Write the simplest IF statement (simplify the Boolean logic) for the following programming problem specification: "Call the UPDATE routine unless: the WORK is not less than zero and the SHAPE is not 'round'." Note that "unless" means "IF NOT TRUE THAT". 39. Write the simplest IF statement (simplify the Boolean logic) for the following programming problem specification: "A STALE sale is one where the DATE is greater than or equal to three years old and the COST is bigger than or equal to zero. If the sale is NOT STALE, call the SHIP routine." 40. Write the simplest IF statement (simplify the Boolean logic) for the following programming problem specification: "In Narnia, you lose (cannot renew) your driving license if your age is 65 or more, or you have 23 or more demerit points. Call the renew() function if this is not true. (Write a simplified IF statement that calls renew() if you are allowed to renew.)" -- | 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/