Boolean Logic & Decision Control: Logic Gate Questions Connected To Code Conditions (Copy)
Logic Gate Questions Connected To Code Conditions (Cambridge Standard – O Level 2210 + IGCSE 0478)
Why Cambridge Connects Logic Gates With Code Conditions
- Logic gates represent:
- The hardware-level equivalent of Boolean logic
- Code conditions represent:
- The software-level implementation of the same logic
- Cambridge tests this link to assess:
- Conceptual understanding (not memorisation)
- Ability to translate logic across representations
- These questions commonly appear as:
- “Write the Boolean expression represented by this logic circuit”
- “Write a condition that matches this logic gate diagram”
- “State when the output will be TRUE”
- “Predict the output for given inputs”
Core Principle You Must Lock In
- Every logic gate diagram can be rewritten as a Boolean condition
- Every Boolean condition can be drawn as logic gates
- There is no difference in meaning, only in representation
Standard Logic Gates Tested By Cambridge
Cambridge expects full understanding of:
| Logic Gate | Boolean Equivalent |
|---|---|
| AND | A AND B |
| OR | A OR B |
| NOT | NOT A |
| NAND | NOT (A AND B) |
| NOR | NOT (A OR B) |
| XOR | A ≠ B (A different from B) |
AND Gate → Code Condition
Logic Gate Meaning
- Output is TRUE only if both inputs are TRUE
Truth Table
| A | B | Output |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| FALSE | FALSE | FALSE |
Equivalent Code Condition
- IF A = TRUE AND B = TRUE THEN
Or simplified:
- IF A AND B THEN
Examiner Focus
- AND gates are commonly used to represent:
- Validation
- Range checking
- Multiple-rule enforcement
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
OR Gate → Code Condition
Logic Gate Meaning
- Output is TRUE if at least one input is TRUE
Truth Table
| A | B | Output |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
Equivalent Code Condition
- IF A = TRUE OR B = TRUE THEN
Simplified:
- IF A OR B THEN
Examiner Trap
- OR is often misused in:
- Range checks
- Loop termination logic
NOT Gate → Code Condition
Logic Gate Meaning
- Output is the inverse of the input
Truth Table
| A | Output |
|---|---|
| TRUE | FALSE |
| FALSE | TRUE |
Equivalent Code Condition
- IF NOT A THEN
Equivalent to:
- IF A = FALSE THEN
Examiner Focus
- NOT gates are commonly applied to:
- Flags
- Loop control variables
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
NAND Gate → Code Condition
Logic Gate Meaning
- NAND = NOT AND
- Output is FALSE only when both inputs are TRUE
Truth Table
| A | B | A AND B | NAND Output |
|---|---|---|---|
| TRUE | TRUE | TRUE | FALSE |
| TRUE | FALSE | FALSE | TRUE |
| FALSE | TRUE | FALSE | TRUE |
| FALSE | FALSE | FALSE | TRUE |
Equivalent Code Condition
- IF NOT (A AND B) THEN
Or expanded:
- IF A = FALSE OR B = FALSE THEN
Examiner Expectation
- Students must recognise:
- NAND is just AND followed by NOT
- De Morgan’s Law is often implicitly tested here
NOR Gate → Code Condition
Logic Gate Meaning
- NOR = NOT OR
- Output is TRUE only when both inputs are FALSE
Truth Table
| A | B | A OR B | NOR Output |
|---|---|---|---|
| TRUE | TRUE | TRUE | FALSE |
| TRUE | FALSE | TRUE | FALSE |
| FALSE | TRUE | TRUE | FALSE |
| FALSE | FALSE | FALSE | TRUE |
Equivalent Code Condition
- IF NOT (A OR B) THEN
Or expanded:
- IF A = FALSE AND B = FALSE THEN
Examiner Focus
- NOR gates are often used to test:
- Logical negation of alternatives
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
XOR Gate → Code Condition (High-Value Concept)
Logic Gate Meaning
- XOR (Exclusive OR) is TRUE when:
- Inputs are different
Truth Table
| A | B | Output |
|---|---|---|
| TRUE | TRUE | FALSE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
Equivalent Code Condition
There is no single operator in Cambridge pseudocode for XOR.
Correct representations:
- IF A ≠ B THEN
Or using Boolean operators:
- IF (A AND NOT B) OR (NOT A AND B) THEN
Examiner Trap
- Students incorrectly write:
- IF A OR B THEN
This is wrong for XOR
- IF A OR B THEN
Converting Logic Gate Diagrams To Code (Step-Based Method)
When given a diagram:
- Identify each gate
- Write Boolean expression for each gate
- Combine expressions step-by-step
- Translate final expression into code condition
Example
Diagram:
- A and B go into AND
- Output goes into NOT
Result:
- NOT (A AND B)
Code:
- IF NOT (A AND B) THEN
Converting Code Conditions To Logic Gates
Given condition:
- IF (A OR B) AND NOT C THEN
Equivalent gates:
- A and B → OR gate
- Output → AND gate with NOT C
Examiner Expectation
- Students should:
- Match structure, not drawing style
- Exact gate positioning is less important than:
- Logical correctness
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Logic Gates In Predict-The-Output Questions
Cambridge may give:
- Inputs for A, B, C
- A logic circuit
- Ask for output value
Correct approach:
- Convert circuit to Boolean expression
- Evaluate expression step-by-step
Example
Expression:
- (A AND B) OR NOT C
Inputs:
- A = TRUE
- B = FALSE
- C = TRUE
Evaluation:
- A AND B → FALSE
- NOT C → FALSE
- FALSE OR FALSE → FALSE
Output:
- FALSE
Logic Gates And Loop Conditions
Logic gates often represent:
- Loop continuation or termination logic
Example circuit:
- index <= 10 AND NOT found
Equivalent code:
- WHILE index <= 10 AND NOT found DO
Examiner Trap
- Replacing AND with OR causes:
- Infinite loops
- Logic gate diagrams highlight this visually
Common Student Errors Cambridge Penalises
- Treating NAND as AND
- Treating NOR as OR
- Using OR instead of XOR
- Ignoring NOT placement
- Translating diagram shape instead of logic meaning
How Cambridge Awards Marks In Logic Gate–Code Questions
- Marks are awarded for:
- Correct Boolean expression
- Correct code condition
- Correct output interpretation
- Partial credit:
- If expression structure is correct
- But minor syntax error exists
Exam Strategy For Logic Gate Questions
- Always rewrite gate diagram as Boolean expression first
- Use brackets generously
- Apply operator precedence consciously
- Do not rely on intuition
- Treat logic gates and code as the same logic
Fast Exam Checklist
- Gate identified correctly?
- NOT applied to correct part?
- AND / OR used correctly?
- XOR logic handled explicitly?
- Final condition matches diagram logic?
Final Quality Checklist
- Correct truth table logic
- Correct Boolean translation
- Correct code condition
- No ambiguity in NOT placement
- Matches Cambridge standards
Final Lock-In Rules
- Logic gates and code conditions are equivalent
- AND = all TRUE
- OR = any TRUE
- NOT = reverse
- NAND / NOR use De Morgan’s logic
- XOR means “different”
- Mastering this link secures Boolean logic marks in Paper 2
