HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
NAND, NOR and XOR Gates and Truth Tables
  1. 1The NAND and NOR gates
  2. 2The XOR gate
  3. 3Completing truth tables
  1. Computer Science
  2. /NAND, NOR and XOR Gates and Truth Tables
  3. /The XOR gate

Course 10.2·Lesson 2 of 3

The XOR gate

The XOR gate gives 1 when its two inputs are different, and 0 when they are the same. You learn its symbol and truth table, how it differs from OR in exactly one row, and how it controls a light from two switches.

about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
NAND, NOR and XOR Gates and Truth Tables
  1. 1The NAND and NOR gates
  2. 2The XOR gate
  3. 3Completing truth tables

Try the code and the simulations beside the lesson.

Two switches, one light

A long staircase has a light switch at the bottom and another at the top. You switch the light on at the bottom and off at the top. Either switch changes the light, whatever the other one is doing. Which gate does that?

The XOR gate

XOR stands for exclusive OR. The syllabus also calls it EOR. It gives 1 when the two inputs are different, and 0 when they are the same.

An XOR gate symbol: the OR shape with a second curved line behind its back. Input A enters at the top left, input B at the bottom left, and the output X leaves on the right.

The symbol is the OR shape with a second curved line behind its back.

A BX = A XOR BA OR B
0 000
0 111
1 011
1 101

The logic expression is X = A XOR B.

Now the stair light. Let the bottom switch be A and the top switch be B. The light is X = A XOR B. Change either switch and the two inputs go from different to the same, or from the same to different. So the light always changes.

XOR and OR differ in one row

Look at the table again. XOR and OR agree in three rows. They differ only in the row 1 1. OR says "at least one", so it gives 1 there. XOR says "one or the other but not both", so it gives 0 there.

XOR from the other gates

You can build XOR from AND, OR and NOT. It is 1 when A is 1 and B is not, or when B is 1 and A is not:

X = (A AND (NOT B)) OR ((NOT A) AND B)

A logic circuit drawn with the standard gate symbols. Inputs A and B are on the left and the output X is on the right. B goes into the first NOT gate; A goes into the second NOT gate; A and the output of the first NOT gate go into the first AND gate; the output of the second NOT gate and B go into the second AND gate; the output of the first AND gate and the output of the second AND gate go into an OR gate, whose output is X. Two wires cross without a dot near the NOT gates, so they are not joined.

Where two wires cross without a dot, they are not joined. A dot marks a point where one wire splits into two.

Check it in the row 0 1: A AND (NOT B) = 0 AND 0 = 0, and (NOT A) AND B = 1 AND 1 = 1. Then 0 OR 1 = 1. That matches XOR. A single XOR gate does the same job as these five gates.

Practise with new numbers

Try it in Python

The program writes XOR with !=, which means "is not equal to". It prints XOR next to OR, then flips a stair switch.

Read it first. Then run it. In which row do XOR and OR differ?

1. Set top, bottom = 0, 0 at the start. Predict both lines of output.

2. Python also has the operator ^ for XOR on 0 and 1. Print 1 ^ 1 and 1 ^ 0.

Common mistakes

  • Using OR when the problem says "but not both". That phrase needs XOR.
  • Thinking XOR gives 1 when both inputs are 1. The inputs are the same then, so XOR gives 0.
  • Drawing XOR with a small circle. XOR has an extra curved line at the back, not a circle.

Remember these

  • XOR (EOR) gives 1 when the inputs differ: output column 0, 1, 1, 0.
  • XOR and OR differ only in the row 1 1.
  • A light worked from two switches is an XOR circuit.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. An XOR gate has A = 1 and B = 1. What is the output?
  1. A rule says "the buzzer sounds when exactly one of the two buttons is pressed". Which gate is it?
  1. In how many rows of its truth table does XOR give 1?
  1. What does the second curved line on a gate symbol tell you?
  1. Spot the mistake. A student says: "XOR is the same as NOR, because both leave out the row 1 1." Is that right?

References

  • Cambridge International, IGCSE Computer Science 0478 syllabus for 2026, 2027 and 2028, topic 10 Boolean logic, and section 4, Logic gate symbols.

Enroll free in NAND, NOR and XOR Gates and Truth Tables

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

A stair light X has a switch A at the bottom and a switch B at the top…Easy · High School (9–10) · by StemPy Lab
A quiz show has two buttons. A judge wants a buzzer X that sounds when exactly one player presses a…Medium · High School (9–10) · by StemPy Lab
The circuit in the picture is built from NOT, AND and OR gates…Hard · High School (9–10) · by StemPy Lab
Next: lesson 3Completing truth tables
← NAND, NOR and XOR Gates and Truth Tables
← The NAND and NOR gatesCompleting truth tables →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.