15-100 Summer 2009
Quiz 0 (Practice)
20 Minutes

  1. Mystery Code / Arithmetic
    Assuming that variables x, y, and z all hold non-negative integer values, under what conditions in general will the following line of code crash?
       int mystery = x / y / z - x / (y / z);
     
  2. Binary Representations
    1. Name two advantages of 2's complement over sign-magnitude
    2. Convert decimal -11 into 5-digit two's complement
    3. What are the largest and smallest values, exactly, in 4-bit 2's complement?
       
  3. Moore's Law
    1. Explain why some calculations involving Moore's Law involve the base-2 logarithm of a number.
    2. Moore's Law has been very accurate for decades now.  Do you think it could still apply in a hundred years?  A billion years?  Why (or why not)?
       
  4. Reading (Chapter 1)
    Note:  every part of Chapter 1 is fair game, even if it is not covered in lectures or on the hw's!
    1. In just a few words, distinguish a LAN from a WAN.
    2. How many bits are required to represent an IP address?  Thus, how many unique IP addresses are there?
    3. Name something that appears in the JDK but not in the JRE.
    4. True or False:  The JRE contains class libraries and the JVM.
       
  5. Sum of Integers
    Write a program that reads in a non-negative integer value, n, and prints out the sum of the integers from 0 to n.  For example, if n equals 3, your code should print out 6 because 0 + 1 + 2 + 3 = 6.  Note: To solve this, you may not use loops (even if you know how)  Instead, you should use Gauss’s Formula:
         0 + 1 + 2 + … + n = (1/2)n2 + (1/2)n
    To verify, if n equals 3, Gauss’s Formula says:
         0 + 1 + 2 + 3 = (1/2)32 + (1/2)3 = 9/2 + 3/2 = 12/2 = 6.
    Yep. Hint: be sure to properly handle integer division and truncation, so that your program produces the correct output for all legal inputs.
     
  6. The Algerian Flag
    Be prepared to paint any of the flags we have covered, or any similar flags, including centering objects in certain areas and rendering crescents, and converting stars to their bounding circles.  For example, try the Algerian flag:

    Actually, you are not responsible for the green portion inside the crescent (why not?).