Courses / Computer Science XI (HSSC-I) – FBISE Complete SLO-Based Course

1.1 Digital Logic, Logic Gates and Truth Tables

Unit 1 – Computer Systems · 80 min read · 10 MCQs to check yourself

Logic gates and truth tables: AND, OR, NOR, XOR, XNOR with examples

1. Analog and digital signals

A signal carries information. A computer can only work with information that is represented electrically.

Feature Analog signal Digital signal
Values Continuous – any value in a range Discrete – only two levels: 0 and 1
Shape Smooth wave (sine wave) Square wave (steps)
Example Human voice, mercury thermometer, old radio Data inside a computer, digital watch, CD/MP3
Noise Noise distorts it easily Very resistant to noise (only HIGH/LOW must be detected)
Processing Hard to store and copy exactly Easy to store, copy, compress and encrypt

A microphone produces an analog signal; an ADC (analog-to-digital converter) samples it and turns it into binary numbers so a computer can store it. A DAC does the opposite for speakers.

2. Digital logic and switches

Digital logic is the part of electronics that works with two states:

Logic 1 Logic 0
TRUE FALSE
HIGH voltage (about 5 V or 3.3 V) LOW voltage (about 0 V)
switch ON / closed switch OFF / open

A switch either lets current flow or stops it. Inside a chip the switches are transistors – billions of them. Two switches in series make an AND (the lamp lights only if both are closed); two switches in parallel make an OR (the lamp lights if either is closed).

3. Logic gates

A logic gate is an electronic circuit with one or more inputs and exactly one output. Its output depends only on the current inputs according to a fixed rule. A truth table lists the output for every possible combination of inputs. With n inputs there are 2ⁿ rows: 2 inputs → 4 rows, 3 inputs → 8 rows.

AND gate – "all inputs must be 1"

Expression: F = A · B (read "A AND B", also written AB).

OR gate – "at least one input is 1"

Expression: F = A + B (read "A OR B"; here + is not addition).

NOT gate (inverter) – "flip the input"

Expression: F = A, also written A' (read "NOT A" or "A bar"). It has only one input.

NAND gate – "NOT of AND"

Expression: F = A · B. The output is 0 only when all inputs are 1. The small circle (bubble) on the output means NOT.

NOR gate – "NOT of OR"

Expression: F = A + B. The output is 1 only when all inputs are 0.

XOR gate – "exclusive OR: inputs are different"

Expression: F = A oplus B = AB + AB. Output is 1 when the inputs are different.

XNOR gate – "equality detector"

Expression: F = A oplus B. Output is 1 when the inputs are the same.

Summary table (2 inputs)

A B AND OR NAND NOR XOR XNOR
0 0 0 0 1 1 0 1
0 1 0 1 1 0 1 0
1 0 0 1 1 0 1 0
1 1 1 1 0 0 0 1

Universal gates: NAND and NOR are called universal because any other gate (AND, OR, NOT, XOR…) can be built using only NAND gates, or only NOR gates. Example: joining both inputs of a NAND gives a NOT gate: A · A = A. Chip factories like universal gates because one gate type is cheaper to mass-produce.

4. Truth tables for expressions (up to 3 inputs)

Method: (1) list all 2ⁿ input combinations in binary counting order 000, 001, 010 … 111; (2) add one column for each sub-expression; (3) work left to right, NOT first, then AND, then OR (the same priority as in algebra: brackets → NOT → AND → OR).

Worked example: F = AB + C

A B C AB C' F = AB + C'
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 1 1
1 1 1 1 0 1

5. Drawing a logic circuit from an expression

Draw one gate for each operator: NOT gates first (near the inputs), then the AND gates for each product term, then one OR gate that combines the terms.

6. Check truth tables with Python

Python has the bitwise operators & (AND), | (OR), ^ (XOR) – for 0/1 values NOT is 1 - x. This short program prints the truth table of F = AB + C and is a good PBA exercise:

print("A B C | F")
for a in (0, 1):
    for b in (0, 1):
        for c in (0, 1):
            f = (a & b) | (1 - c)
            print(a, b, c, "|", f)

Output:

A B C | F
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

7. Logic gates in daily life

Application How gates are used
Car seat-belt alarm AND: alarm = engine ON AND belt NOT fastened
Bank locker / two-key safe AND: opens only when both keys are turned
Home alarm / burglar alarm OR: alarm if door sensor OR window sensor is triggered
Staircase light (two switches) XOR: either switch toggles the lamp
Calculator / CPU adder XOR + AND form a half adder (sum = A XOR B, carry = A AND B)
Automatic street lights NOT: light ON when the light sensor reads NOT bright
Password / equality check XNOR compares bits – all 1s means the values are equal
Washing machine, microwave Combinations of gates decide when to start, stop or beep

Practical (PBA) tasks

  1. Use an online simulator such as Logic.ly, CircuitVerse or Falstad to build AND, OR, NOT, NAND, NOR, XOR circuits with switches and LEDs; record the truth table for each.
  2. Build F = AB + C in the simulator and compare it with the table above.
  3. Show that NAND is universal: build NOT, AND and OR using only NAND gates.
  4. Write a Python program that prints the truth table of any 3-input expression you choose.

Logic gates and circuit diagrams – drawing circuits from expressions

Short and long questions

1. Differentiate between analog and digital signals with one example of each.

Model answer
Analog signal Digital signal
Continuous – can take any value in a range Discrete – only two levels, 0 and 1
Smooth wave shape Square (step) wave
Easily affected by noise Resistant to noise
Example: human voice, mercury thermometer Example: data in a computer, digital watch

2. Draw OR and NAND gates with their truth tables.

Model answer

OR gate (F = A + B) – curved shield shape with two inputs.

A B F
0 0 0
0 1 1
1 0 1
1 1 1
NAND gate (F = (AB)') – AND shape with a small circle (bubble) at the output.
A B F
--- --- ---
0 0 1
0 1 1
1 0 1
1 1 0

3. How are logic gates useful in daily life? Give any three applications.

Model answer
  1. Car seat-belt alarm – AND gate: alarm = engine ON AND belt NOT fastened.
  2. Burglar alarm – OR gate: the alarm rings if the door sensor OR the window sensor is triggered.
  3. Staircase light – XOR: either of two switches can turn the same light on or off. Others: calculators/CPUs use XOR and AND as adders; street lights use NOT with a light sensor; bank lockers need two keys (AND).

4. Construct the truth table for F = AB + C'.

Model answer
A B C AB C' F
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 1 1
1 1 1 1 0 1

This lesson ends with a quiz of 10 MCQs. Open the lesson on PrepOasis to take it and save your progress.

Previous: Practical Based Assessment (PBA) – Lab Tasks, Practical Exam and Viva · Next: 1.2 Boolean Algebra, Identities, Duality and Karnaugh Maps

All lessons in Computer Science XI (HSSC-I) – FBISE Complete SLO-Based Course