Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🖥️ Unit 1 – Computer Systems & Organisation  ·  Lesson 07

Boolean Logic, Gates & Truth Tables

What is Boolean logic?

Boolean logic (named after George Boole) works with only two values: True (1) and False (0). A Boolean expression combines these values using operations like NOT, AND and OR. Every decision inside a computer — "is the password correct?", "is marks ≥ 33?" — finally becomes Boolean logic in electronic circuits called logic gates.

🏠 Real-life example

A room light controlled by two switches in series turns on only if switch 1 AND switch 2 are on. A doorbell with two buttons (front and back door) rings if button 1 OR button 2 is pressed.

Symbols used: NOT A is written A' or Ā; A AND B is A·B; A OR B is A + B; A XOR B is A ⊕ B.

Logic gates at a glance

ABYANDABYORAYNOTABYNANDABYNORABYXOR
Standard symbols of the six gates (a small circle means NOT)

NOT, AND, OR

NOT gate (inverter)

One input; the output is the opposite. Y = A'.

AY = A'
01
10

AND gate

Output is 1 only when all inputs are 1. Y = A·B. Think: "pass only if theory AND practical are cleared".

ABY = A·B
000
010
100
111

OR gate

Output is 1 when at least one input is 1. Y = A + B. Think: "entry allowed with ID card OR fee receipt".

ABY = A + B
000
011
101
111

NAND and NOR (universal gates)

NAND = AND followed by NOT: Y = (A·B)'. Output is 0 only when both inputs are 1. NOR = OR followed by NOT: Y = (A + B)'. Output is 1 only when both inputs are 0.

ABNAND (A·B)'NOR (A+B)'
0011
0110
1010
1100

They are universal: for example, connecting both inputs of a NAND gate together gives a NOT gate, because (A·A)' = A'. Chips are cheaper to make when only one kind of gate is used.

XOR (exclusive OR)

Output is 1 when the inputs are different. Y = A ⊕ B = A'B + AB'. Example: a staircase light with one switch at the bottom and one at the top — flipping either switch changes the light.

ABY = A ⊕ B
000
011
101
110

All truth tables with Python

In Python, the bitwise operators & (AND), | (OR) and ^ (XOR) work on 0 and 1, so we can print every table in a few lines:

Python
print('A B | AND OR XOR NAND NOR')
for A in (0, 1):
    for B in (0, 1):
        AND = A & B
        OR = A | B
        XOR = A ^ B
        print(A, B, '|', AND, '  ', OR, ' ', XOR, '  ', 1 - AND, '   ', 1 - OR)
A B | AND OR XOR NAND NOR 0 0 | 0 0 0 1 1 0 1 | 0 1 1 1 0 1 0 | 0 1 1 1 0 1 1 | 1 1 0 0 0

Boolean laws

LawAND formOR form
IdentityA · 1 = AA + 0 = A
Null (domination)A · 0 = 0A + 1 = 1
IdempotentA · A = AA + A = A
ComplementA · A' = 0A + A' = 1
Involution (double NOT)(A')' = A
CommutativeA · B = B · AA + B = B + A
Associative(A · B) · C = A · (B · C)(A + B) + C = A + (B + C)
DistributiveA · (B + C) = A·B + A·CA + B·C = (A + B)(A + C)
AbsorptionA · (A + B) = AA + A·B = A
🧮 Solved example

Simplify Y = A·B + A·B'. → A·(B + B') (distributive) → A·1 (complement) → A (identity).

De Morgan’s laws

First law

  • (A · B)' = A' + B'
  • NOT of AND = OR of the NOTs
  • NAND = "bubbled" OR

Second law

  • (A + B)' = A' · B'
  • NOT of OR = AND of the NOTs
  • NOR = "bubbled" AND
Break the bar, change the sign

Proof by truth table — check that both sides are equal for every row. Python can do all rows for us:

Python
# Check De Morgan's laws for every combination
ok = True
for A in (False, True):
    for B in (False, True):
        law1 = (not (A and B)) == ((not A) or (not B))
        law2 = (not (A or B)) == ((not A) and (not B))
        print(A, B, law1, law2)
        ok = ok and law1 and law2
print('Both laws hold:', ok)
False False True True False True True True True False True True True True True True Both laws hold: True

Logic circuits and expressions

A logic circuit joins gates together. To find its truth table, write the output expression and evaluate it for every input combination. Example: Y = (A·B) + C' — one AND gate, one NOT gate and one OR gate.

A, BinputsANDA·BOR(A·B) + C'Youtput
C passes through a NOT gate and enters the OR gate as C'
Python
# Y = (A AND B) OR (NOT C)
print('A B C | Y')
for A in (0, 1):
    for B in (0, 1):
        for C in (0, 1):
            Y = (A and B) or (not C)
            print(A, B, C, '|', int(Y))
A B C | Y 0 0 0 | 1 0 0 1 | 0 0 1 0 | 1 0 1 1 | 0 1 0 0 | 1 1 0 1 | 0 1 1 0 | 1 1 1 1 | 1

Three inputs → 2³ = 8 rows. Y is 1 whenever C is 0, and also when A and B are both 1.

Summary & practice

  • Boolean values: 0 and 1. Operations: NOT (A'), AND (A·B), OR (A+B), XOR (A⊕B).
  • NAND and NOR are universal gates.
  • n inputs → 2ⁿ rows in the truth table.
  • De Morgan: (A·B)' = A' + B', (A+B)' = A'·B'.
✅ Practice

1) Draw the truth table of Y = A' + B. 2) Simplify A + A'B. 3) Which gate gives 1 only when both inputs are 0?

Answers: 1) rows 00→1, 01→1, 10→0, 11→1. 2) A + B (using A + A'B = (A + A')(A + B)). 3) NOR.

Frequently Asked Questions

Why are NAND and NOR called universal gates?
Because any other gate — NOT, AND, OR, XOR — and therefore any digital circuit can be built using only NAND gates, or only NOR gates.
How many rows does a truth table have?
For n inputs there are 2ⁿ rows. Two inputs give 4 rows, three inputs give 8 rows.
What are De Morgan’s laws?
(A·B)' = A' + B' and (A + B)' = A' · B'. In words: NOT of AND equals OR of NOTs, and NOT of OR equals AND of NOTs.
← Class 11 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicEmerging Trends: AI, IoT, Cloud Your progress: 7 / 29 (24%) · Lesson 8 / 29 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free