## CPSC 120 -- Test #2 Review

### Topics

• Machine Representation of Integers (Class notes, handout on twos complement, Lab 5 Prelab and Lab, exercise handouts, Section 2.3 and Appendix B of the text)
• Be able to convert a number in any base to its equivalent base 10 representation.
• Be able to convert a base 10 number to any other base.
• Be able to convert among bases 2 (binary), 8 (octal), and 16 (hexadecimal) without using base 10.
• Be able to find the n-bit (where n is specified) twos complement representation of a base 10 integer (positive or negative).
• Be able to find the base 10 value of a number represented in twos complement.
• Be able to find the largest (and smallest) base 10 unsigned number that can be stored in n-bits; be able to find the largest (and smallest) base 10 signed twos complement number that can be stored in n-bits.
• Be able to add base 2 and twos complement numbers; understand the problem of overflow (what it means and how to recognize it) and be able to demonstrate it.

• Selection Statements and Boolean Expressions (Sections 4.1 - 4.4 of the text plus handouts, labs and prelabs)
• Know how to write if ... else ... statements in their various forms (with no else clause, nested, cascading). Know when you need to use braces!!!
• Know how to write and evaluate boolean expressions using relational operators (such as == and <=) and boolean operators (&&, ||, and !); know that the relational operators such as == work only on primitive data not on objects (to compare objects you must use methods - equals or compareTo).
• Know about the boolean data type -- how to declare a boolean variable and assign the result of a boolean expression to the variable.
• Know how to write a method with a boolean return type.
• Know that the switch statement is another selection statement that can be used when your selection condition is to test to see if a single variable is equal to one of several different possible values (the cases in the switch). Understand the role of the break statement in the switch -- without it once a condition is true all remaining statements in the switch would be executed rather than just the one where the condition is true. You will not have to write a switch statement on the test but you may be asked some general question or given a switch statement and asked something about it.
• Be able to trace code with if statements, switch statements, and boolean expressions to show what it would do (or to determine if it is correct).

• Logic (Handouts - one labeled "Logic" and one labeled "Logic and Programming Exercises")
• Know the logic operators AND, OR, and NOT and both the mathematical and Java symbols for these.
• Be able to construct truth tables for boolean expressions (propositions/ logic statements).
• Know DeMorgan's law of logic - be able to use it both on mathematical statements and in the context of programming.
• Be able to show two boolean expressions are equivalent using truth tables.
• Be able to use the laws of logic (DeMorgan's, Distributive, Idempotent, etc.) to simplify statements.
• Understand the connection between logic and computer circuits. In particular, be able to write a logic statement equivalent to a given circuit, be able to use the laws of logic to simplify the statement and construct a simpler but equivalent circuit, be able to constuct a circuit given either a truth table for its output or a verbal description of the behavior of the circuit.

• While Loops (Section 4.5 & Lab 7)
• Understand how loops work - be able to trace the execution of a loop showing the value of each variable as the loop executes and/or showing the output of the loop.
• Be able to write loops. In particular, be able to correctly do each part that goes into writing a loop:
• write the correct boolean expression for the loop control condition
• initialize variables before the loop
• update the loop control variable(s) inside the loop
• perform the processing inside the loop (do whatever the loop is supposed to do!)
• Specifically be able to write loops that do the following standard looping tasks: count, sum, find averages, force the user to enter valid input, find products.
• Know how to recognize and write count-controlled loops and sentinel controlled loops.

• Testing (Lab 6)
• Be able to determine test cases to test a program (a) when there are many different paths through a program (such as Rock, Paper, Scissors) and (b) when a value should be in a specific range (such as the Date program).