📘 CodingMarble Learn

Boolean Logic

Boolean logic works with only two values: 1 (true) and 0 (false). Logic gates act on them: NOT flips a value; AND gives 1 only if all inputs are 1; OR gives 1 if any input is 1; NAND and NOR are the opposites of AND and OR; XOR gives 1 when inputs differ. A truth table lists the output for every input combination (2ⁿ rows for n inputs). De Morgan's laws: (A·B)' = A' + B' and (A + B)' = A'·B'. Gates joined together form logic circuits that match Boolean expressions.

🎬 Step-by-step story

  1. NOT flips the input. 1 becomes 0 and 0 becomes 1. A lit switch means 1.
  2. AND gives 1 only when both inputs are 1. Only the last row lights the lamp.
  3. OR gives 1 when at least one input is 1. Only 0 and 0 keeps the lamp off.
  4. NAND is the opposite of AND. NOR is the opposite of OR. XOR gives 1 when the inputs are different.
  5. De Morgan: NOT(A AND B) is the same as NOT A OR NOT B. Check all four rows: both lamps match.
  6. Your turn: pick a gate, flip A and B, and watch the lamp.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Why only 0 and 1?

A computer's circuits have just two clear states: current flows (1) or it does not (0). Boolean logic works with exactly these two.

Why does AND stay off when only one switch is on?

AND needs every input to be 1. Watch the rows 0,1 and 1,0: the lamp stays dark.

Is 1 + 1 = 2 in OR?

No. In Boolean logic + means OR, and 1 OR 1 = 1. There is no 2.

How is XOR different from OR?

They differ only in the last row: OR(1,1) = 1 but XOR(1,1) = 0.

Why is De Morgan's law true?

'Not both' means 'at least one is not'. Watch both circuits give the same lamp in all four rows.

Boolean values and logic gates: NOT, AND, OR

Boolean logic (after George Boole) has only two values: 1 = true, 0 = false. A logic gate is a tiny circuit that takes Boolean inputs and gives one output.

NAND, NOR and XOR gates

NAND and NOR are called universal gates because any other gate can be built using only NAND gates (or only NOR gates).

Truth tables

A truth table lists every combination of inputs and the output. With n inputs there are 2n rows (2 inputs → 4 rows, 3 inputs → 8 rows).

ABANDORNANDNORXOR
0000110
0101101
1001101
1111000

NOT: A = 0 → 1, A = 1 → 0.

De Morgan's laws

Law 1: (A·B)' = A' + B' — NOT of an AND equals OR of the NOTs.

Law 2: (A + B)' = A'·B' — NOT of an OR equals AND of the NOTs.

Proof by truth table: write columns for A, B, A·B, (A·B)', A', B', A' + B'. The columns (A·B)' and A' + B' are 1, 1, 1, 0 in every row, so they are equal. Law 2 is checked the same way.

Trick: break the bar over the whole expression, put a bar on each variable, and change · to + (or + to ·).

Logic circuits

A logic circuit joins gates so the output of one becomes the input of another. Every circuit matches a Boolean expression.

Example: X = A·B + C'. The circuit has an AND gate for A·B, a NOT gate for C, and an OR gate that joins the two results.

To draw a circuit from an expression: do the innermost brackets and NOTs first, then AND, then OR (just like BODMAS, NOT has the highest priority, then AND, then OR). To find the expression from a circuit: write the output of each gate, moving left to right.

Board exam focus

Expect: draw the truth table of a 2- or 3-input expression, prove De Morgan's law by truth table (3 marks), draw the circuit for an expression like (A + B)·C', write the expression of a given circuit.

Key formulas and definitions

Worked examples

1. Find the output of A·B + A' when A = 0, B = 1.

A·B = 0·1 = 0. A' = 1. Output = 0 + 1 = 1.

2. How many rows does the truth table of a 3-input expression have?

2³ = 8 rows.

3. Make the truth table of X = (A + B)'.

A=0,B=0: A+B=0 → X=1. A=0,B=1: 1 → 0. A=1,B=0: 1 → 0. A=1,B=1: 1 → 0. This is the NOR gate.

4. Prove (A + B)' = A'·B' using a truth table.

Rows (A,B): 00, 01, 10, 11. A + B: 0,1,1,1 → (A+B)': 1,0,0,0. A': 1,1,0,0; B': 1,0,1,0 → A'·B': 1,0,0,0. Both columns are 1,0,0,0, so the law is proved.

5. Simplify using De Morgan: (A'·B)'.

(A'·B)' = (A')' + B' = A + B'.

6. Draw (in words) the circuit for X = (A·B) + (B'·C) and find X when A=1, B=0, C=1.

Gates: AND1(A, B); NOT(B); AND2(B', C); OR(AND1, AND2). A·B = 0; B' = 1; B'·C = 1; X = 0 + 1 = 1.

Common mistakes

Practice quiz

1. Which gate gives 1 only when all inputs are 1?
2. Output of XOR when A = 1, B = 1:
3. (A + B)' equals:
4. Which are universal gates?
5. Rows in the truth table for 4 inputs:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What are the basic logic gates?

NOT, AND and OR are basic gates. NAND, NOR and XOR are built from them; NAND and NOR are universal gates.

What are De Morgan's laws?

(A·B)' = A' + B' and (A + B)' = A'·B'. The complement of a product is the sum of complements and vice versa.

How many rows are in a truth table?

2ⁿ rows for n inputs: 4 for 2 inputs, 8 for 3 inputs.

Where this is taught

NetherlandsHAVO 5 (eindexamenjaar)Elective theme: Computer architecture
NetherlandsVWO 6 (eindexamenjaar)Elective theme: Computer architecture
Spain4º ESOTechnological operators
Ukraine10 класElective: mathematical foundations of informatics (35 h)
Ukraine11 класElective: mathematical foundations of informatics (35 h)
CBSE (India)Class 11Computer Systems and Organisation
England (GCSE, A level)Year 113.4 Computer systems
England (GCSE, A level)Year 124.6 Fundamentals of computer systems
England (GCSE, A level)Year 134.6-4.7 Computer systems and architecture (A-level)
Russia8 классTheoretical foundations
Russia8 классTheoretical foundations
Russia10 классTheoretical foundations
Russia10 классTheoretical foundations
China高二Sel.1 Electronic control technology (engineering series)

Learn first

Learn next

Related lessons

All Computer Science lessons