Logic Basics: AND, OR, NOT
Logic is central to controlling the order in which instructions are executed in computer programs. in this module you will learn to use the logical operators AND, OR and NOT, which allow programmers to specify conditions which determine the flow of control.
The contents of these pages can be downloaded as a (non-interactive) PDF file from here.
True and False
Computer programs contain statements or conditions that can be true or false (but not both at once), so we begin with simple statements that are either true or false (but not both).
Logic is at the heart of computers; it is needed to understand how single bits are manipulated in the CPU. The most basic of operations are logic operations.
Logic is needed for programming to ensure that the correct statements are executed, and executed in the correct order.
The truth value of a statement is “true” if it is true and “false” if it is false. Here are some simple statements together with their truth values:
- 1 + 1 = 2. This is true.
- 45 < 50. This is true.
- 1 + 1 = 4. This is false.
- If our friend Jane is 20 years old then the statement “Jane is at least 18 years old” is true.
We sometimes write $T$ for true and $F$ for false.
Here are some practice questions for you to try. You will be directed to the next page based on your responses to these questions.
|The capital city of Australia is Perth.|