Learn Digital Logic

From basic gates to flip-flops — everything you need to master digital circuit design.

What is Digital Logic?

Digital logic is the foundational concept behind all modern computational devices, from simple calculators to advanced supercomputers. It is the mathematical framework based on Boolean algebra that allows electronic circuits to process binary information—ones and zeros, representing high and low voltages.

At its core, digital logic involves using microscopic electronic switches (transistors) arranged into "gates." These gates perform basic logical operations like AND, OR, and NOT. By combining thousands or millions of these simple building blocks, engineers create combinational circuits (like adders and multiplexers) for processing data, and sequential circuits (like flip-flops and registers) for storing memory.

Understanding digital logic is essential for anyone interested in computer science, computer engineering, or electronics. It bridges the gap between hardware and software, revealing exactly how a computer thinks and processes information at the physical level.

Logic Gates Reference

Logic gates are the basic building blocks of any digital system. Here is a comprehensive reference to the standard logic gates, their symbols, truth tables, and Boolean expressions.

AND Gate

The AND gate outputs a high signal (1) only if all of its inputs are high. Otherwise, it outputs a low signal (0).

F = A · B
ABOutput
000
010
100
111
Try in Simulator →

OR Gate

The OR gate outputs a high signal (1) if any of its inputs are high. It outputs a low signal (0) only if all inputs are low.

F = A + B
ABOutput
000
011
101
111
Try in Simulator →

NOT Gate (Inverter)

The NOT gate, or inverter, simply reverses the input state. If the input is high (1), the output is low (0), and vice versa.

F = A'
AOutput
01
10
Try in Simulator →

NAND Gate

The NAND gate is a universal gate. It behaves exactly opposite to the AND gate. It outputs low (0) only if all inputs are high (1).

F = (A · B)'
ABOutput
001
011
101
110
Try in Simulator →

NOR Gate

The NOR gate is also universal. It behaves oppositely to the OR gate. It outputs high (1) only if all inputs are low (0).

F = (A + B)'
ABOutput
001
010
100
110
Try in Simulator →

XOR Gate

The Exclusive-OR (XOR) gate outputs high (1) only when its inputs are different. It is widely used in arithmetic circuits.

F = A ⊕ B
ABOutput
000
011
101
110
Try in Simulator →

XNOR Gate

The Exclusive-NOR (XNOR) gate outputs high (1) only when its inputs are identical. It acts as an equality comparator.

F = (A ⊕ B)'
ABOutput
001
010
100
111
Try in Simulator →

BUFFER Gate

A buffer outputs exactly what is input into it. It doesn't change the logic state but is used to amplify signals or add delay.

F = A
AOutput
00
11
Try in Simulator →

Boolean Algebra Laws

Boolean algebra uses rules to simplify logical expressions, which helps in reducing the number of gates needed in a digital circuit.

Identity Law
A + 0 = A
A · 1 = A
Null Law
A + 1 = 1
A · 0 = 0
Idempotent Law
A + A = A
A · A = A
Complement Law
A + A' = 1
A · A' = 0
Commutative Law
A + B = B + A
A · B = B · A
Associative Law
(A+B)+C = A+(B+C)
(A·B)·C = A·(B·C)
Distributive Law
A·(B+C) = (A·B)+(A·C)
A+(B·C) = (A+B)·(A+C)
De Morgan's Theorems
(A + B)' = A' · B'
(A · B)' = A' + B'

Combinational Circuits

Combinational logic circuits have outputs that depend exclusively on their current inputs. They possess no memory. Common examples include adders, decoders, and multiplexers.

Half Adder

A half adder is a combinational circuit that adds two single binary digits (A and B). It produces two outputs: a sum (S) and a carry (C). While fundamental, it cannot accept a carry-in from a previous addition stage.

ABSum (S)Carry (C)
0000
0110
1010
1101
Load in Simulator →

Full Adder

A full adder expands on the half adder by accommodating a carry-in (Cin) bit from a previous addition. It adds three bits (A, B, Cin) and produces a Sum and a Carry-out, enabling the chaining of adders to compute multi-bit numbers.

ABCinSumCout
01010
01101
11111
...and so on
Load in Simulator →

2:1 Multiplexer (MUX)

A multiplexer (MUX) is a digital switch. A 2:1 MUX takes two data inputs (I0, I1) and a single select line (S). Based on the select line's state, it routes one of the inputs to the output. It acts as a data selector.

SOutput (Y)
0I0
1I1
Load in Simulator →

2-to-4 Decoder

A decoder transforms binary information from 'n' input lines to a maximum of 2^n unique output lines. A 2-to-4 decoder takes a 2-bit input and activates exactly one of its four outputs corresponding to the binary value of the input.

A1A0Y0Y1Y2Y3
001000
010100
100010
110001
Load in Simulator →

Sequential Circuits & Flip-Flops

Unlike combinational circuits, sequential circuits have memory. Their output depends on both current inputs and the previous state. Flip-flops are the fundamental memory elements.

SR Flip-Flop

The Set-Reset (SR) flip-flop is the simplest memory unit. It has Set and Reset inputs. When S is 1, it stores a 1. When R is 1, it stores a 0. The state where both S and R are 1 is generally invalid or unpredictable.

SRQ(next)State
00Q(prev)Hold
010Reset
101Set
11?Invalid
Load in Simulator →

D Flip-Flop

The Data (D) flip-flop eliminates the invalid state of the SR flip-flop. It simply captures the value of the D input at a specific portion of the clock cycle (e.g., rising edge) and holds it until the next cycle. It's widely used in registers.

ClockDQ(next)
00
11
0/1XQ(prev)
Load in Simulator →

JK Flip-Flop

The JK flip-flop improves upon the SR flip-flop by making the J=1, K=1 condition valid. When both inputs are 1, it toggles its current state. It is highly versatile and forms the basis for many counter circuits.

JKQ(next)State
00Q(prev)Hold
010Reset
101Set
11Q(prev)'Toggle
Load in Simulator →

T Flip-Flop

The Toggle (T) flip-flop changes its state only when the T input is 1. If T is 0, it holds its state. It is primarily built from a JK flip-flop with tied inputs and is used extensively in binary counters and frequency dividers.

TQ(next)State
0Q(prev)Hold
1Q(prev)'Toggle
Load in Simulator →

Karnaugh Maps (K-Maps)

A Karnaugh Map (K-Map) is a visual tool used to simplify Boolean algebra expressions without using complex theorems. By arranging truth table outputs in a grid based on Gray code, K-Maps allow you to identify overlapping groups of 1s (or 0s), leading directly to a minimized logic circuit.

Example: 3-Variable K-Map

F(A,B,C) layout

A \ BC 00 01 11 10
0 m0 m1 m3 m2
1 m4 m5 m7 m6