Logic Gates

Logic gates are the building blocks of digital circuits. They perform basic logical operations on binary inputs.

Basic Gates

AND Gate

Output is 1 only when ALL inputs are 1

Truth Table:
A | B | Output
0 | 0 |   0
0 | 1 |   0
1 | 0 |   0
1 | 1 |   1

OR Gate

Output is 1 when ANY input is 1

Truth Table:
A | B | Output
0 | 0 |   0
0 | 1 |   1
1 | 0 |   1
1 | 1 |   1

NOT Gate

Inverts the input (1→0, 0→1)

Truth Table:
A | Output
0 |   1
1 |   0

Universal Gates

NAND Gate (Universal)

NOT + AND. Output is 0 only when ALL inputs are 1

A | B | Output
0 | 0 |   1
0 | 1 |   1
1 | 0 |   1
1 | 1 |   0

NOR Gate (Universal)

NOT + OR. Output is 1 only when ALL inputs are 0

A | B | Output
0 | 0 |   1
0 | 1 |   0
1 | 0 |   0
1 | 1 |   0

Other Gates

XOR Gate (Exclusive OR)

Output is 1 when inputs are DIFFERENT

A | B | Output
0 | 0 |   0
0 | 1 |   1
1 | 0 |   1
1 | 1 |   0

XNOR Gate

Output is 1 when inputs are SAME

A | B | Output
0 | 0 |   1
0 | 1 |   0
1 | 0 |   0
1 | 1 |   1

Adder Circuits

Half Adder

Adds two 1-bit numbers. Outputs: Sum and Carry

A | B | Sum | Carry
0 | 0 |  0  |   0
0 | 1 |  1  |   0
1 | 0 |  1  |   0
1 | 1 |  0  |   1

Sum = A XOR B
Carry = A AND B

Full Adder

Adds three 1-bit numbers (A, B, Carry-in)

A | B | Cin | Sum | Cout
0 | 0 |  0  |  0  |  0
0 | 0 |  1  |  1  |  0
0 | 1 |  0  |  1  |  0
0 | 1 |  1  |  0  |  1
1 | 0 |  0  |  1  |  0
1 | 0 |  1  |  0  |  1
1 | 1 |  0  |  0  |  1
1 | 1 |  1  |  1  |  1

Propositional Logic

Propositional logic deals with statements that are either true or false.

Well-Formed Formulae (WFF)

Rules for creating valid logical expressions:

  • • A propositional variable (p, q, r) is a WFF
  • • If A is a WFF, then ¬A (NOT A) is a WFF
  • • If A and B are WFFs, then (A ∧ B), (A ∨ B), (A → B) are WFFs
Examples of WFF:
p
¬p
(p ∧ q)
((p ∨ q) → r)

Not WFF:
p ∧ ∧ q
(p q)

Truth Tables

Example: (p ∧ q) ∨ ¬r

p | q | r | ¬r | p∧q | (p∧q)∨¬r
0 | 0 | 0 | 1  |  0  |    1
0 | 0 | 1 | 0  |  0  |    0
0 | 1 | 0 | 1  |  0  |    1
0 | 1 | 1 | 0  |  0  |    0
1 | 0 | 0 | 1  |  0  |    1
1 | 0 | 1 | 0  |  0  |    0
1 | 1 | 0 | 1  |  1  |    1
1 | 1 | 1 | 0  |  1  |    1

Number Systems

Understanding different number bases and conversions.

Number Bases

Binary (Base 2): 0, 1
Octal (Base 8): 0-7
Decimal (Base 10): 0-9
Hexadecimal (Base 16): 0-9, A-F

Conversions

Decimal to Binary

Example: 13₁₀ to Binary
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Result: 1101₂

Binary to Decimal

Example: 1101₂ to Decimal
1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 8 + 4 + 0 + 1 = 13₁₀

Binary Addition

  1011
+  110
------
 10001

Rules: 0+0=0, 0+1=1, 1+1=10

Key Points

  • • NAND and NOR are universal gates
  • • XOR outputs 1 when inputs differ
  • • Half adder: adds 2 bits, Full adder: adds 3 bits
  • • WFF must follow logical syntax rules
  • • Binary uses base 2, Hex uses base 16