You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
The XOR gate (exclusive OR) takes two inputs and produces an output of 1 only when the inputs are different. XOR is a crucial gate in computer science, used extensively in encryption and arithmetic circuits. This is covered in OCR J277 Section 2.5.
XOR stands for exclusive OR. Unlike the standard OR gate (which outputs 1 when at least one input is 1), XOR outputs 1 only when exactly one input is 1 — that is, when the inputs are different from each other.
In Boolean algebra, XOR is written as:
The word "exclusive" means it excludes the case where both inputs are 1.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Compare this with the OR truth table — the only difference is the last row. When both inputs are 1, OR outputs 1 but XOR outputs 0.
| A | B | OR | XOR |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 |
OCR Exam Tip: The key difference between OR and XOR is the last row. OR gives 1 when both inputs are 1; XOR gives 0. Think of XOR as "one or the other, but not both."
The XOR gate symbol looks like the OR gate but with an extra curved line on the input side:
A ----\\ /---- Q
|| XOR |
B ----// \
The double curved line on the left distinguishes XOR from OR. In the exam, you must draw this extra line to get the mark.
Python does not have a dedicated xor keyword for Boolean values, but you can use the != operator or the bitwise ^ operator:
# XOR using != (not equal)
a = True
b = False
result = a != b # True (because they are different)
print(result)
# XOR using bitwise ^ operator
x = 1
y = 0
print(x ^ y) # 1
In OCR pseudocode, XOR may be expressed as:
a = true
b = false
if a != b then
print("Inputs are different")
endif
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.