Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Competitions › SOF ICSO › unit 2 of 16

Logic gates

SOF ICSO · Computer Science · about 6 minutes

Logic gates are the tiny decisions inside every chip. AND needs both inputs on; OR needs at least one; NOT flips its input.

Switch the inputs and watch the output wire and the truth table.

In this lesson

  1. Gates are tiny decisions
  2. Truth tables
  3. Useful rules
  4. Worked examples
  5. Where marks are lost
  6. Check yourself

1Gates are tiny decisions

A logic gate takes inputs of 0 or 1 and gives one output. AND gives 1 only if all inputs are 1. OR gives 1 if at least one input is 1. NOT flips its single input.

NAND and NOR are AND and OR followed by NOT. XOR gives 1 when the inputs are different.

2Truth tables

A truth table lists every combination of inputs: 2 inputs give 4 rows, 3 inputs give 8 rows (2ⁿ).

For a circuit of several gates, add a column for each gate’s output and work left to right.

3Useful rules

De Morgan: NOT (A AND B) = (NOT A) OR (NOT B), and NOT (A OR B) = (NOT A) AND (NOT B).

NAND alone can build every other gate, which is why chips use it so much.

Worked examples

  1. Example 1What is the output of (A AND B) OR (NOT C) when A = 1, B = 0, C = 0?

    1. A AND B = 1 AND 0 = 0.
    2. NOT C = 1.
    3. 0 OR 1 = 1.

    Answer: 1

  2. Example 2For which inputs does a NOR gate give 1?

    1. OR gives 0 only when both inputs are 0.
    2. NOR flips that.

    Answer: Only A = 0, B = 0

See it move

Where marks are lost

  • Mixing up NAND and NOR.
  • Forgetting a row in a truth table: count 2ⁿ rows.
  • Treating XOR as OR when both inputs are 1.

Exam tips

  • AND is like multiplication of 0s and 1s.
  • OR is 0 only when both inputs are 0.
  • NAND (NOT AND) can build every other gate.

Practice questions

  1. An AND gate has inputs 1 and 0. Output?

  2. An OR gate has inputs 0 and 0. Output?

  3. Output of NOT(1 AND 1)?

More worked examples

Try each one first, then open the working.

  1. What is the output Y? Type 0 or 1.

    ORA = 0B = 0Y = ?
    Show the working

    Start: Work through the circuit from left to right.

    OR with inputs 0 and 0 gives 0.

    Answer: 0

  2. Complete the truth table for the NOR gate. What is the missing output? Type 0 or 1.

    NORABYABY00101010011?
    Show the working

    Start: Apply the gate rule to the two inputs in that row.

    NOR(1, 1) = 0.

    Answer: 0

  3. Find Y = A·B + A′·C when A = 1, B = 1, C = 1. Type 0 or 1. (′ means NOT)

    Show the working

    Start: NOT first, then AND, then OR.

    Substitute and work inside the brackets first: Y = 1.

    Answer: 1

  4. What is the output Y? Type 0 or 1.

    NORA = 0B = 0Y = ?
    Show the working

    Start: Work through the circuit from left to right.

    NOR with inputs 0 and 0 gives 1.

    Answer: 1

Practise more

New questions every time, at exam level

What is the output Y? Type 0 or 1.

NORA = 1B = 0Y = ?

Sit a timed SOF ICSO mock test

Binary numbersNext: Tracing a program