CS 101 review questions

Test your comprehsion of the material with these questions. Most of these come directly from examples in class. A great way to prepare for a test is for you to come up with your own questions and check your answers. You can practice doing this with some of my review questions below.

Note that in the case of yes/no questions, you should be able to justify your answer. In general, being able to explain your reasoning is more important than simply stating an answer, which you could forget or accidentally get wrong.


  1. Write down a bit string having 6 bits. What number does this bit string represent in the following representation schemes?
  2. Practice this question with a bit string that starts with a 1, and a bit string that starts with a 0.

    Answer: Let's try the bit string 100110. This is the binary code for:

    Now let's look at a bit string that starts with 0. Consider 010101. This is the binary code for:

     

  3. Pick a two digit number (integer). Determine the 8-bit representations for this number using the following representation schemes
  4. Practice this question also with a two digit negative number.

    Answer: Let's consider the number 59. If we write this number as a sum of powers of 2 (which we would get on our receipt if we shopped at the "binary store", we have 59 = 32+16+8+2+1.

    Now let's try -59.

     

  5. The single-precision floating-point representation is a method of representing real numbers. We allocate 8 bits for the exponent. Explain how we can determine the approximate bound for the largest possible (finite) number that we can represent, and the smallest positve number.
  6. Answer: If we have 8 bits for the exponent, then we have about 2^8 = 256 possible values for the exponent. These exponents should be evenly divided between positive and negative exponents. Thus, the largest power of 2 we can use is about 2^128. It's more convenient to work using base 10, and since log 2 is about .301, we have 2^128 ~= 10^38. This is an approximate maximum value. Similarly, the smallest positive number will be the negative exponent: 10^-38.

    If we had instead used 7 bits for the exponents, then we would start with about 128 possible exponents, with the largest possible exponent value about 64. Then, 2^64 is about 10^19. The most minuscule positive number would analogously be about 10^-19. The question asks us to consider if this would be practical for science. It would not, because in many applicatons in chemistry and physics we need to express values with larger exponents than 19 (and less than -19). Some famous examples are: Avogadro's number which uses 10^23, and the mass of an electron which is on the order of 10^-31 kg.

  7. This question features some approximate values for large powers of 2. These approximations will appear in brackets. You may find the question easier to grasp initially in terms of these approximate values than just the powers of 2.
    Using the fact that the mantissa for a single-precision floating-point number has 23 bits:
  8. Answer: Let's continue to use the approximation that 2^20 = 1 million

     

  9. The binary number 110.1001 equals what base-10 number? If we multiply this binary number by 4, what is the binary result?
  10. Answer: 4 + 2 + (1/2) + (1/16) = 6-9/16 (i.e. six and nine-sixteenths) or 9.5625

    If you multiply by 4, note that 4 = 2^2, so move the "." by 2 places to the right to obtain 11010.01.

  11. In what ways did typical computers of the 1980s differ from those of the 1950s? How do today's PCs differ from those of 20 years ago?
  12.  

  13. If the ASCII code for 'A' is 65, what symbol has ASCII code 85?
  14. Answser: 'A' is the first letter of the alphabet. If we add 20 to its ASCII code, we want the 21st letter, which is 'U'.

  15. The ASCII codes for 'a' and '0' (zero) are 97 and 48, respectively. What is the ASCII code for '3' ? What is the ASCII code for '6' ? The value '3' + '3' is the ASCII code for what letter? When you ask the computer for 3+3, how come it knows to give you 6 as the answer instead of a letter?
  16. Answer: The ASCII code for '3' is '0' + 3 = 48+3 = 51. Similarly, the ASCII code for '6' is '0'+6 = 48 + 6 = 54.

    '3' + '3' = 51+51 = 102. If 'a' = 97 then we want the letter which is (102-97=) 5 letters after 'a' which is 'a' + 5 = 'f'.

    When we ask the computer to add 3+3, the machine can distinguish between numbers and text. It can tell we are entering numbers. But the machine needs to be told in advance to expect numerical rather than text input. This is why cells in Excel have a "format" that we can specify. Fortunately, in Excel by default if you enter something that looks like a number, Excel will automatically format it to be a number instead of text.

  17. Basic image properties:
  18.  

  19. Give example RGB codes for light green, medium green and dark green.

  20. When we use indexed color, we often express the R,G and B values in hexadecimal, and the values we can choose are 00, 33, 66, 99, cc and ff. What color is represented by the code #cc0000?
  21.  

  22. Using indexed color and dithering, explain how we can approximate a background color close to the value #993355.
  23.  

  24. Convert this arithmetic expression to postfix notation: (1+2) * (3+4).
  25. Answer: 1 2 + 3 4 + *

  26. Suppose an XOR gate has two inputs x and y and an output z. If x = 1 and z = 1, is it possible for us to determine the value of y? If so, what is it?
  27.  

  28. Consider a NAND gate with two inputs x and y and an output z. If x = y, then what can we conclude about z?
  29. Answer: Note that NAND returns the opposite of AND. Consider x = y = 0. In this case, AND would output 0, so NAND outputs 1. If x = y = 1, then AND returns 0, so NAND returns 0. Putting these two cases together, we see that if x = y, then the output (z) of the gates is the opposite of the input. In other words, all we have created is a NOT gate.

  30. Suppose a machine does 8-bit signed integer arithmetic. Give an example of a computation that will result in overflow. Is underflow possible?
  31. Answer: Note that the range of possible values is -128 to +127. We just need to pose a question whose correct answer is outside this range. For example, 100+100. Underflow is only possible in real-number arithmetic, not integer arithmetic.

  32. Draw finite automata that accept these sets of binary strings:
  33.  

  34. Write regular expressions that describe these sets of strings:
  35. Answers:

     

  36. Suppose that a processor's speed is 2 GHz. Each instruction that executes needs to undergo 5 stages, and each stage takes 1 cycle of CPU time. How many instructions can we execute in 1 microsecond if the machine is: