--
Days Left
Chapter 01

Number Systems

The foundation of Digital Logic β€” understanding Binary, Octal, Decimal, and Hexadecimal number systems, their conversions, and arithmetic operations.

Number System Bases

SystemBaseDigits UsedExample
Binary20, 1(1010)β‚‚ = 10
Octal80–7(12)β‚ˆ = 10
Decimal100–9(10)₁₀ = 10
Hexadecimal160–9, A–F(A)₁₆ = 10
Why Binary? Computers use binary because electronic circuits have exactly two stable states β€” ON (1) and OFF (0). Transistors act as switches representing these two states. All computations, memory, and data transfer happen in binary at the hardware level.

Decimal to Binary Conversion

Repeatedly divide by 2 and collect remainders from bottom to top (LSB first).

decimal-to-binary: 25
25 Γ· 2 = 12  remainder 1   ← LSB (Least Significant Bit β€” rightmost)
12 Γ· 2 = 6   remainder 0
6  Γ· 2 = 3   remainder 0
3  Γ· 2 = 1   remainder 1
1  Γ· 2 = 0   remainder 1   ← MSB (Most Significant Bit β€” leftmost)

// Read remainders from BOTTOM to TOP:
(25)₁₀ = (11001)β‚‚

// Verify: 1Γ—16 + 1Γ—8 + 0Γ—4 + 0Γ—2 + 1Γ—1 = 16+8+1 = 25 βœ“
Most Common Exam Mistake Always read remainders from BOTTOM to TOP (LSB to MSB). Reading top to bottom gives the wrong answer. After conversion, always verify by converting back to decimal.

Binary to Decimal Conversion

Multiply each bit by its positional power of 2, then sum all values.

binary-to-decimal: (1101)β‚‚
Position:  3    2    1    0    ← position number (right = 0)
Bit:       1    1    0    1

= 1Γ—2Β³  +  1Γ—2Β²  +  0Γ—2ΒΉ  +  1Γ—2⁰
= 1Γ—8   +  1Γ—4   +  0Γ—2   +  1Γ—1
= 8     +  4     +  0     +  1
= 13

(1101)β‚‚ = (13)₁₀

πŸ“Š Quick Reference: Powers of 2 & Hex Table

2ⁿValueHex DigitDecimalBinary
2⁰ = 11A101010
2ΒΉ = 22B111011
2Β² = 44C121100
2Β³ = 88D131101
2⁴ = 1616E141110
2⁡ = 3232F151111
2⁢ = 6464β€”β€”β€”
2⁷ = 128128β€”β€”β€”

1's and 2's Complement

Complement notation is used to represent negative numbers and to perform binary subtraction.

complement.c
// 1's Complement: Flip every bit (0β†’1, 1β†’0)
(1010)β‚‚  β†’  (0101)β‚‚  ← 1's Complement

// 2's Complement: 1's Complement + 1
  0101
+    1
──────
  0110   ← 2's Complement of (1010)β‚‚

// Binary Subtraction using 2's Complement:
// A - B  =  A + (2's complement of B)
Example: 8 - 3 = ?
8 = 1000
3 = 0011 β†’ 1's comp = 1100 β†’ 2's comp = 1101
1000 + 1101 = 10101 β†’ drop carry β†’ 0101 = 5 βœ“
2's Complement Shortcut From the rightmost bit, copy all bits up to and including the first 1 exactly as they are. Then flip (invert) all remaining bits to the left.

Example: 1 0 1 0 β†’ Copy "10" from right β†’ flip rest β†’ 0 1 1 0

Octal & Hexadecimal Conversions

octal-hex-conversion
// Binary ↔ Octal: Group bits in sets of 3 from right
(101 110 011)β‚‚
= (5   6   3)β‚ˆ = (563)β‚ˆ

// Binary ↔ Hex: Group bits in sets of 4 from right
(1010 1111 0011)β‚‚
= (A    F    3)₁₆ = (AF3)₁₆

// Decimal to Hex: Divide by 16
255 Γ· 16 = 15 r 15 (F)
15  Γ· 16 = 0  r 15 (F)
β†’ (255)₁₀ = (FF)₁₆
Chapter 02

Codes β€” BCD, Gray, ASCII

Different coding techniques used in digital systems to represent data in a way that minimizes errors, simplifies arithmetic, or enables communication.

BCD (Binary Coded Decimal)

In BCD, each individual decimal digit is represented separately using 4 binary bits. It is different from pure binary β€” (12)₁₀ in BCD is 0001 0010, NOT (1100)β‚‚.

DecimalBCDDecimalBCD
0000050101
1000160110
2001070111
3001181000
4010091001
BCD Addition
// (39)₁₀ in BCD: encode each digit separately
3 β†’ 0011,   9 β†’ 1001
BCD = 0011 1001

// BCD Addition Rule: If sum of a digit group > 9, add 0110 (6)
  0111  (7)
+ 0110  (6)
──────
  1101  ← 13 in binary, but 13 > 9 in BCD context!
+ 0110  ← Add 6 correction factor
──────
1 0011  ← 1 (carry) | 0011 (3) β†’ BCD of 13 βœ“
BCD Invalid Codes β€” Exam Important! BCD only uses codes 0000 (0) through 1001 (9). The codes 1010 (10) through 1111 (15) are INVALID in BCD β€” they do not represent any valid BCD digit. When these appear after addition, apply the +0110 correction rule.

Gray Code

Gray Code is a binary numbering system where adjacent values differ by exactly only one bit. This property minimizes switching errors in mechanical and digital systems.

DecimalBinaryGray CodeBit Changed
0000000β€”
1001001LSB
2010011Bit 1
3011010LSB
4100110MSB
5101111LSB
6110101Bit 1
7111100LSB
Binary to Gray Code Conversion
// Rule: MSB stays the same. Each subsequent bit = XOR of adjacent binary bits
Binary:     1  0  1  1
           ↓  ↓  ↓  ↓
MSB:        1              ← copy as is
1 XOR 0:      1
0 XOR 1:         1
1 XOR 1:            0

Gray Code: 1  1  1  0

// Gray to Binary (reverse): MSB same, each bit = XOR with previous gray bit
Gray:   1  1  1  0
Binary: 1
1 XOR 1 = 0
0 XOR 1 = 1
1 XOR 0 = 1
Binary: 1  0  1  1 ← back to original βœ“
Why Gray Code is Used In shaft encoders and mechanical position sensors, if multiple bits change at once (like in regular binary from 0111β†’1000), glitches can occur during the transition. Gray code ensures only one bit changes at a time, eliminating these transition errors entirely.

ASCII Code

  • ASCII = American Standard Code for Information Interchange
  • Uses 7 bits β†’ can represent 128 characters (0 to 127)
  • Extended ASCII uses 8 bits β†’ 256 characters
  • Covers: uppercase letters, lowercase letters, digits, special characters, control codes
CharacterASCII (Decimal)ASCII (Hex)ASCII (Binary)
'A'65411000001
'Z'905A1011010
'a'97611100001
'z'1227A1111010
'0'48300110000
'9'57390111001
Space32200100000
Key Trick β€” Uppercase vs Lowercase The difference between any uppercase letter and its lowercase version is exactly 32. So 'A'(65) + 32 = 'a'(97). To convert case, just flip bit 5 (the 32-bit position). This is why it's called a "5-bit trick" in some references.
Chapter 03

Logic Gates

Logic gates are the fundamental building blocks of digital circuits. They take binary inputs and produce a binary output based on a specific logical function. All digital systems β€” from simple calculators to modern CPUs β€” are built from combinations of these gates.

πŸ”© Basic Gates β€” AND, OR, NOT

ABAND (AΒ·B)OR (A+B)NOT (Δ€)
00001
01011
10010
11110
Easy Memory Rules AND = "All must be 1" β€” output is 1 only when ALL inputs are 1
OR = "Any one is enough" β€” output is 1 when AT LEAST ONE input is 1
NOT = "Invert everything" β€” flips 0 to 1 and 1 to 0 (single input only)

Universal Gates β€” NAND and NOR

ABNANDNORXOR (βŠ•)XNOR
001101
011010
101010
110001
Exam Must Know β€” Universal Gates Both NAND and NOR are called "Universal Gates" because ANY logic function can be implemented using ONLY NAND gates, or ONLY NOR gates. This makes them extremely cost-effective in chip manufacturing β€” you only need to produce one type of gate.

XOR rule: Output is 1 when inputs are DIFFERENT (odd number of 1s)
XNOR rule: Output is 1 when inputs are SAME (even number of 1s, including zero)

πŸ› οΈ Implementing Other Gates Using NAND

NAND-implementation
// NOT using NAND: connect both inputs together
NOT(A) = NAND(A, A)    // Single NAND gate, both inputs = A

// AND using NAND: NAND then NOT the result
AND(A,B) = NAND[NAND(A,B), NAND(A,B)]   // 2 NAND gates

// OR using NAND: invert both inputs then NAND
OR(A,B)  = NAND[NAND(A,A), NAND(B,B)]   // 3 NAND gates

// NOR using NAND: build OR then invert
NOR(A,B) = NAND[OR(A,B), OR(A,B)]       // 4 NAND gates total

// Same logic applies for NOR as Universal Gate:
NOT(A) = NOR(A, A)
OR(A,B) = NOR[NOR(A,B), NOR(A,B)]
AND(A,B) = NOR[NOR(A,A), NOR(B,B)]
Why This Matters In VLSI (chip design), manufacturing only one type of gate (NAND) reduces cost and complexity. The entire CPU in your computer is fundamentally billions of NAND gates working together.
Chapter 04

Boolean Algebra

Boolean Algebra is the mathematical framework for working with logical expressions. It provides rules and laws to simplify complex logic circuits, reducing the number of gates needed and lowering cost and power consumption.

πŸ“ Boolean Laws (Complete Reference)

Law NameAND FormOR Form
Identity LawA Β· 1 = AA + 0 = A
Null / Dominance LawA Β· 0 = 0A + 1 = 1
Idempotent LawA Β· A = AA + A = A
Complement LawA Β· Δ€ = 0A + Δ€ = 1
Double ComplementΔ€Μ„ = A (NOT of NOT = original)
Commutative LawAΒ·B = BΒ·AA+B = B+A
Associative Law(AΒ·B)Β·C = AΒ·(BΒ·C)(A+B)+C = A+(B+C)
Distributive LawAΒ·(B+C) = AΒ·B + AΒ·CA+(BΒ·C) = (A+B)Β·(A+C)
Absorption LawAΒ·(A+B) = AA + AΒ·B = A
Consensus TheoremAΒ·B + Δ€Β·C + BΒ·C = AΒ·B + Δ€Β·C
Absorption Law β€” Very Useful for Simplification A + AΒ·B = A β€” you can absorb the extra term completely. This is because A already "includes" AΒ·B (wherever A=1, AΒ·B can be 0 or 1 but it doesn't add anything new). Similarly AΒ·(A+B) = A because A AND anything that includes A is just A.

βš–οΈ De Morgan's Theorem

De Morgan's theorems are the most important tool for simplifying logic expressions, especially when converting between NAND/NOR implementations.

De-Morgans-Laws
// First Theorem: "Break the bar, change the operator"
Μ„(AΒ·B) = Δ€ + BΜ„
// NOT(AND) = OR of NOTs β†’ NAND = NOT-AND

// Second Theorem:
Μ„(A+B) = Δ€ Β· BΜ„
// NOT(OR) = AND of NOTs β†’ NOR = NOT-OR

// Extended De Morgan: works for any number of variables
Μ„(AΒ·BΒ·C) = Δ€ + BΜ„ + CΜ„
Μ„(A+B+C) = Δ€ Β· BΜ„ Β· CΜ„

// Simplification Example:
F = Μ„(AΒ·B) + Μ„(A+C)
  = (Δ€+BΜ„)  + (Δ€Β·CΜ„)    ← apply De Morgan to each term
  = Δ€ + BΜ„ + Δ€Β·CΜ„        ← expand
  = Δ€(1+CΜ„) + BΜ„          ← factor out Δ€
  = Δ€Β·1 + BΜ„             ← (1+CΜ„) = 1 by Null Law
  = Δ€ + BΜ„               ← final simplified form
De Morgan's Rule β€” Never Forget This When you break a bar over a group: the AND becomes OR (or OR becomes AND), AND every variable under the bar gets complemented individually.

"Break the bar β†’ change the operation β†’ complement all variables"

SOP and POS Forms

SOP-POS
// SOP (Sum of Products) = Minterm form
// Take rows where output F = 1, AND the variables, then OR all terms
// If variable = 1 in that row β†’ use A, if 0 β†’ use Δ€

// Truth Table: F = Ξ£m(1,2,3) [minterms where F=1]
Row: A B | F
     0 0 | 0
     0 1 | 1  β†’ Δ€Β·B
     1 0 | 1  β†’ AΒ·BΜ„
     1 1 | 1  β†’ AΒ·B

F (SOP) = Δ€Β·B + AΒ·BΜ„ + AΒ·B

// POS (Product of Sums) = Maxterm form
// Take rows where output F = 0, OR the variables, then AND all terms
// If variable = 0 in that row β†’ use A, if 1 β†’ use Δ€

Row: 0 0 β†’ (A+B)     ← complement of 0,0
F (POS) = (A+B)
Which Form to Use? Use SOP (minterms) when there are fewer 1s in the truth table β€” fewer terms to write. Use POS (maxterms) when there are fewer 0s. Both forms are equivalent and represent the same function. K-Map is used to simplify SOP expressions to minimum form.
Chapter 05

Karnaugh Map (K-Map)

The K-Map is a visual method for minimizing Boolean expressions without using algebraic manipulation. It is the most exam-heavy topic in Digital Logic β€” expect at least one question on it every year.

K-Map Rules

  • Group only 1s together (for SOP minimization)
  • Group sizes must be powers of 2 only: 1, 2, 4, 8, 16
  • Make groups as large as possible β€” larger groups eliminate more variables
  • Groups can and should overlap β€” a cell can belong to multiple groups
  • The map wraps around β€” left/right edges connect, top/bottom edges connect, and even corners connect
  • Don't-care values (X or d) can be treated as 1 or 0, whichever makes the group larger
  • Every 1 must be covered by at least one group β€” no 1 can be left uncovered
Critical: Gray Code Order! K-Map columns/rows use Gray Code order: 00, 01, 11, 10 β€” NOT 00, 01, 10, 11. The 11 and 10 are swapped. This ensures adjacent cells differ by only one variable, which is essential for the grouping logic to work correctly.

2-Variable K-Map

2-variable-kmap
         B=0   B=1
         ─────────────
A=0  |   mβ‚€  |   m₁  |
A=1  |   mβ‚‚  |   m₃  |

// Example: F = Ξ£m(0,1,3) β†’ F=1 at mβ‚€, m₁, m₃

         B=0   B=1
         ─────────────
A=0  |   1   |   1   |   ← Group 1: pair mβ‚€,m₁ (top row, B varies β†’ Δ€)
A=1  |   0   |   1   |   ← Group 2: pair m₁,m₃ (right column, A varies β†’ B)

Groups:
  Group 1 (mβ‚€,m₁): A=0 constant, B varies β†’ term = Δ€
  Group 2 (m₁,m₃): B=1 constant, A varies β†’ term = B

F = Δ€ + B

3-Variable K-Map

3-variable-kmap
// 3-var: rows = C, columns = AB in Gray Code order

        AB=00  AB=01  AB=11  AB=10
        ──────────────────────────
C=0  |   mβ‚€  |  mβ‚‚  |  m₆  |  mβ‚„  |
C=1  |   m₁  |  m₃  |  m₇  |  mβ‚…  |

// Example: F = Ξ£m(0,1,2,3,4)
        AB=00  AB=01  AB=11  AB=10
C=0  |   1   |   1  |   0  |   1  |
C=1  |   1   |   1  |   0  |   0  |

// Group 1 (Octet impossible): mβ‚€,m₁,mβ‚‚,m₃ form a Quad β†’ AB=00,01 both rows
//   A=0 constant β†’ term = Δ€
// Group 2: mβ‚€,mβ‚„ (first and last column) β€” wrap around!
//   C=0, B=0 constant β†’ term = CΜ„Β·BΜ„

F = Δ€ + BΜ„Β·CΜ„

// Grouping elimination rule:
// Pair (2 cells)  β†’ eliminates 1 variable
// Quad (4 cells)  β†’ eliminates 2 variables
// Octet (8 cells) β†’ eliminates 3 variables

4-Variable K-Map Layout

4-variable-kmap
// 4 variables A,B,C,D β†’ rows = AB, columns = CD (Gray Code)

         CD=00  CD=01  CD=11  CD=10
         ─────────────────────────────────
AB=00 |   mβ‚€  |   m₁  |   m₃  |   mβ‚‚  |
AB=01 |   mβ‚„  |   mβ‚…  |   m₇  |   m₆  |
AB=11 |  m₁₂  |  m₁₃  |  m₁₅  |  m₁₄  |
AB=10 |   mβ‚ˆ  |   m₉  |  m₁₁  |  m₁₀  |

// Corner grouping example: mβ‚€,mβ‚‚,mβ‚ˆ,m₁₀ form a Quad (four corners!)
// B=0, D=0 constant β†’ term = BΜ„Β·DΜ„
Don't-Care Conditions Don't-care cells (marked X or d) are outputs that can never occur in normal operation (e.g., BCD codes 1010–1111 are never used). In K-Map, treat them as 1 if it helps make a larger group, or as 0 if they don't help. Using don't-cares cleverly results in much simpler final expressions.
Chapter 06

Combinational Circuits

In combinational circuits, the output depends only on the current input β€” there is no memory or feedback. The output changes immediately whenever the input changes. Key examples: adders, subtractors, multiplexers, decoders, and encoders.

Half Adder

Adds two single bits. Has two inputs (A, B) and two outputs (Sum and Carry). It CANNOT handle a carry input from a previous stage.

ABSum (S)Carry (C)
0000
0110
1010
1101
Half Adder equations
Sum   = A XOR B  =  A βŠ• B       // Use XOR gate
Carry = A AND B  =  A Β· B        // Use AND gate

// Hardware: 1 XOR gate + 1 AND gate = Half Adder
// Limitation: No Carry-in input β€” cannot chain multiple stages

Full Adder

Adds three bits β€” two data bits (A, B) plus a Carry-In (Cin) from the previous stage. Used in multi-bit binary addition by chaining multiple Full Adders together (called a Ripple Carry Adder).

ABCinSumCout
00000
00110
01010
01101
10010
10101
11001
11111
Full Adder equations
Sum  = A βŠ• B βŠ• Cin
Cout = AΒ·B + BΒ·Cin + AΒ·Cin
     = AΒ·B + CinΒ·(AβŠ•B)          // Simplified form

// Full Adder can be built from 2 Half Adders + 1 OR gate:
HA1: S1 = AβŠ•B,       C1 = AΒ·B
HA2: Sum = S1βŠ•Cin,   C2 = S1Β·Cin
Cout = C1 + C2
Exam Key Difference Half Adder has 2 inputs (A, B) β€” no carry-in β€” used for the least significant bit only.
Full Adder has 3 inputs (A, B, Cin) β€” handles carry from previous stage β€” used for all higher bit positions in multi-bit addition.

A 4-bit adder needs: 1 Half Adder (for bit 0) + 3 Full Adders (for bits 1, 2, 3).

Multiplexer (MUX)

A multiplexer selects one of many input signals and forwards it to the output, based on the selection lines. It is also called a "Data Selector."

  • 2:1 MUX β€” 2 data inputs, 1 select line, 1 output
  • 4:1 MUX β€” 4 data inputs, 2 select lines, 1 output
  • 8:1 MUX β€” 8 data inputs, 3 select lines, 1 output
  • General: 2ⁿ data inputs require n selection lines
4:1 MUX equation
// 4:1 MUX with inputs Iβ‚€,I₁,Iβ‚‚,I₃ and select lines S₁,Sβ‚€
Y = Δͺ₁·Δͺβ‚€Β·Iβ‚€ + Δͺ₁·Sβ‚€Β·I₁ + S₁·Δͺβ‚€Β·Iβ‚‚ + S₁·Sβ‚€Β·I₃

// Selection truth table:
S₁ Sβ‚€  |  Output
─────────────────
 0  0  |   Iβ‚€
 0  1  |   I₁
 1  0  |   Iβ‚‚
 1  1  |   I₃

// MUX as Universal Function Generator:
// Connect variables to select lines, 0/1 to data inputs
// Any function of n variables can be realized with a 2ⁿ:1 MUX

Decoder and Encoder

  • Decoder (n:2ⁿ): Takes n-bit input and activates exactly one of 2ⁿ output lines. Example: 3:8 decoder has 3 inputs and 8 outputs, activating the output line corresponding to the binary value of the input.
  • Encoder (2ⁿ:n): The opposite of a decoder β€” converts one of 2ⁿ active input lines to an n-bit binary code. Example: 8:3 encoder converts 8-line input to 3-bit binary output.
  • Priority Encoder: When multiple inputs are active simultaneously, the encoder outputs the binary code of the highest-priority (usually highest-numbered) active input. Adds a V (valid) output to indicate at least one input is active.
  • BCD to 7-Segment Decoder: Converts a 4-bit BCD digit (0–9) to the 7 signals needed to light up the correct segments on a 7-segment display.
Decoder Generating Minterms A 3:8 decoder generates all 8 minterms of 3 variables. By connecting specific decoder outputs to an OR gate, any Boolean function can be implemented. This makes decoders very useful for circuit implementation from truth tables.
Chapter 07

Sequential Circuits

Unlike combinational circuits, sequential circuits have memory. The output depends not only on the current input but also on the previous state. They are the foundation of registers, counters, and all memory elements in computers.

Combinational vs Sequential β€” Key Differences

FeatureCombinationalSequential
MemoryNo β€” statelessYes β€” stores state
Output depends onCurrent inputs onlyCurrent inputs + Previous state
Clock signalNot requiredRequired (usually)
FeedbackNo feedback pathsOutput fed back to input
ExamplesAdder, MUX, DecoderFlip-Flop, Counter, Register
Analysis toolTruth tableState diagram / State table

Synchronous vs Asynchronous Sequential Circuits

  • Synchronous: All flip-flops are triggered by the same clock signal edge. State changes happen only at the clock edge. Predictable, easy to design and analyze. Most modern digital systems are synchronous.
  • Asynchronous: State changes happen immediately when inputs change β€” no clock needed. Faster response, but harder to design. Race conditions and hazards are common problems.
  • Positive Edge Triggered: Circuit responds on the rising edge of the clock (0β†’1 transition)
  • Negative Edge Triggered: Circuit responds on the falling edge of the clock (1β†’0 transition)
Latch vs Flip-Flop β€” A Key Distinction A Latch is level-triggered β€” it responds to the clock level (passes data when clock=1, holds when clock=0). It can have transparent behavior that leads to glitches.

A Flip-Flop is edge-triggered β€” it only samples and stores data at the precise instant of a clock edge. This makes it much more reliable and predictable in synchronous systems. Most modern circuits use edge-triggered flip-flops.

State Diagrams and State Tables

Sequential circuits are analyzed using state diagrams (bubbles = states, arrows = transitions) and state tables (tabular form showing next state and output for each state/input combination).

State Table Structure
// State table format: Present State | Input | Next State | Output

Present State | Input X | Next State | Output Z
─────────────────────────────────────────────────
     S0       |    0    |    S0      |    0
     S0       |    1    |    S1      |    0
     S1       |    0    |    S0      |    0
     S1       |    1    |    S2      |    1
     S2       |    0    |    S0      |    1
     S2       |    1    |    S2      |    1

// Mealy Machine: Output depends on state AND input
// Moore Machine: Output depends ONLY on state (not input)
Chapter 08

Flip-Flops

A flip-flop is the basic memory cell in digital circuits β€” it stores exactly one bit of information. Different types of flip-flops (SR, D, JK, T) offer different behavior and are used in different applications.

πŸ”§ SR Flip-Flop (Set-Reset)

The simplest flip-flop. S=Set forces output to 1, R=Reset forces output to 0. When S=R=0, the previous state is maintained (memory).

SRQ (next)QΜ„ (next)Operation
00QQΜ„No change β€” hold state
0101Reset β€” output becomes 0
1010Set β€” output becomes 1
11?? FORBIDDEN β€” undefined!
SR Flip-Flop's Fatal Flaw When S=1 and R=1, both outputs Q and QΜ„ are forced to 1 simultaneously. This violates the rule that Q and QΜ„ must always be complements of each other. The resulting state is undefined and unpredictable. This forbidden state is the main reason the JK flip-flop was invented β€” it solves this problem by defining a valid behavior for J=K=1 (toggle).

JK Flip-Flop

The most versatile flip-flop. It corrects the SR flip-flop's forbidden state problem by defining J=K=1 as a toggle operation (output flips to its complement).

JKQ (next)Operation
00QNo change β€” hold state
010Reset β€” output becomes 0
101Set β€” output becomes 1
11QΜ„Toggle β€” output complements! ← key advantage
JK β€” The Universal Flip-Flop The JK FF can simulate all other flip-flops:
β†’ Set J=K=T to get T Flip-Flop behavior (toggle)
β†’ Set J=D, K=DΜ„ to get D Flip-Flop behavior (data latch)
β†’ Set J=S, K=R to get SR Flip-Flop behavior (but J=K=1 is now valid toggle instead of forbidden)

The JK FF is the most commonly used flip-flop in practice.
Race-Around Condition in JK FF In level-triggered JK FFs, when J=K=1 and clock is HIGH for too long, the output toggles multiple times uncontrollably (races around). Solution: use edge-triggered (master-slave) JK flip-flops, which only respond at the clock edge and avoid this problem entirely.

D Flip-Flop (Data / Delay)

D (input)Q (next)Operation
00Stores 0
11Stores 1
D Flip-Flop
Q(next) = D    ← Output simply follows the input D at clock edge

// D FF eliminates the forbidden state by using D and DΜ„ directly
// Built from SR FF: S = D,  R = DΜ„ (they are always opposite)
// Primary use: data registers, memory cells, pipeline registers
// Also called "Delay FF" because output is delayed by one clock cycle

T Flip-Flop (Toggle)

T (input)Q (next)Operation
0QNo change β€” hold state
1QΜ„Toggle β€” output flips
T Flip-Flop
Q(next) = T βŠ• Q    ← XOR of T and current state

// Built from JK FF: J = K = T
// Primary use: counters, frequency dividers
// When T=1 permanently, FF toggles every clock cycle
// β†’ output frequency = clock frequency / 2 (binary divide-by-2)
T Flip-Flop in Counters A chain of T flip-flops (all with T=1) naturally counts in binary. Each FF divides the frequency by 2, so 4 T-FFs produce a 4-bit binary counter (0000 to 1111) with each bit being double the period of the previous. This is the basis of ripple counters.

Flip-Flop Conversion Summary

Convert FROM β†’ TORequired Logic
JK β†’ DJ = D, K = DΜ„ (invert D for K)
JK β†’ TJ = T, K = T (connect same signal to both)
JK β†’ SRJ = S, K = R (direct mapping)
D β†’ JKD = JΒ·QΜ„ + KΜ„Β·Q (use characteristic equation)
D β†’ TD = T βŠ• Q
D β†’ SRD = S + RΜ„Β·Q (must ensure SΒ·R = 0)
T β†’ DT = D βŠ• Q
T β†’ JKT = JΒ·QΜ„ + KΒ·Q
Chapter 09

Registers & Counters

Registers and counters are practical sequential circuits built from flip-flops. Registers store and transfer multi-bit data; counters advance through a sequence of binary states with each clock pulse.

Shift Registers

A shift register is a chain of D flip-flops connected so that each clock pulse shifts data one position in the chain. They are used for serial-to-parallel conversion, data delay, and generating sequences.

TypeFull FormDescriptionUse Case
SISOSerial In, Serial OutData enters one bit at a time, exits one bit at a time. Acts as a time delay element.Time delay, pipeline
SIPOSerial In, Parallel OutData enters serially, but all bits are available simultaneously at the output after n clocks.Serial-to-parallel conversion (UART receiver)
PISOParallel In, Serial OutAll bits loaded simultaneously, then shifted out one-by-one serially.Parallel-to-serial conversion (UART transmitter)
PIPOParallel In, Parallel OutAll bits loaded and available simultaneously. Acts as a simple data register.CPU registers, data storage
Bidirectional Shift Register A bidirectional shift register can shift data either left or right, controlled by a direction select line. It can perform multiplication (left shift = multiply by 2) and division (right shift = divide by 2) in binary β€” a key operation in ALUs.

Counters β€” Types and Properties

Counter TypeKey PropertySpeedNotes
Ripple (Asynchronous)Flip-flops trigger each other in sequenceSlow β€” delay accumulates with each stageSimple to build, but propagation delay increases with bit width
SynchronousAll FFs share the same clock β€” toggle simultaneouslyFast β€” no cumulative delayMore hardware needed (logic gates for each FF), but preferred in practice
Up CounterCounts 0 β†’ 1 β†’ 2 β†’ ... β†’ Max β†’ 0β€”Normal counting direction
Down CounterCounts Max β†’ ... β†’ 1 β†’ 0 β†’ Maxβ€”Decrements on each clock
Up-Down CounterCounts either direction based on controlβ€”Has a direction control input
BCD Counter (Mod-10)Cycles 0 β†’ 9 β†’ 0 β†’ ...β€”Resets after reaching 9 (1001); counts 10 states
Ring CounterSingle 1 rotates through all FFsβ€”Built from a shift register in a loop; self-decoding, n FFs = n states
Johnson (Twisted Ring)Complement fed back; 2n states from n FFsβ€”Better than ring counter β€” more states per FF
Counter Modulus Calculation
// n-bit counter cycles through 2ⁿ states
2-bit counter: Mod-4  β†’ states: 00, 01, 10, 11
3-bit counter: Mod-8  β†’ states: 000 to 111
4-bit counter: Mod-16 β†’ states: 0000 to 1111

// To build a Mod-N counter where N is NOT a power of 2:
// Use enough FFs for the next higher power of 2, then reset when count = N
Mod-6  counter: use 3 FFs (Mod-8 base), reset at binary 6 (110)
Mod-10 counter: use 4 FFs (Mod-16 base), reset at binary 10 (1010)

// Ring Counter: n FFs β†’ n states (0001, 0010, 0100, 1000 for 4-bit)
// Johnson Counter: n FFs β†’ 2n states
Chapter 10

Memory

Memory stores binary data in digital systems. Understanding the different types, their properties (volatile vs non-volatile, read-write vs read-only), and how to calculate memory size is essential for both exams and real-world computing.

Memory Types β€” Complete Reference

TypeFull FormVolatile?Writable?Use
RAMRandom Access MemoryYes β€” data lost on power offYes β€” freelyMain working memory (programs, data)
ROMRead Only MemoryNo β€” data permanentNo β€” factory programmedBIOS, firmware, boot code
PROMProgrammable ROMNoOnce only β€” by user with a programmerOne-time field programming
EPROMErasable PROMNoYes β€” erase with UV light, then reprogramDevelopment and prototyping
EEPROMElectrically Erasable PROMNoYes β€” erase and write electrically, byte by byteConfiguration storage, settings
FlashFlash MemoryNoYes β€” erase and write in sectors/blocksUSB drives, SSDs, SD cards
Volatile vs Non-Volatile Volatile memory loses all data when power is removed (RAM, cache). Non-volatile memory retains data even without power (ROM, Flash, EEPROM). When your computer shuts down, RAM content is lost; your SSD content is preserved.

SRAM vs DRAM β€” Critical Comparison

PropertySRAM (Static RAM)DRAM (Dynamic RAM)
Storage elementFlip-flop (6 transistors/cell)Capacitor + transistor (1 transistor/cell)
SpeedVery fast (1–10 ns)Slower (50–70 ns)
CostVery expensiveCheap
DensityLow β€” large cellsHigh β€” tiny cells
Refresh needed?No β€” holds state as long as poweredYes β€” capacitors leak, must refresh every ~64ms
Power consumptionHigher (idle)Lower, but extra for refresh
Typical useCPU cache (L1, L2, L3)Main memory (RAM sticks in PC)
🚨 SRAM vs DRAM β€” Exam Must Know SRAM is fast but expensive β†’ used in small amounts as CPU cache.
DRAM is slow but cheap and dense β†’ used in large amounts as main memory.

Key fact: DRAM capacitors lose charge over time due to leakage, requiring periodic refresh circuits to recharge them β€” this is why DRAM is "dynamic." SRAM uses flip-flops which hold state indefinitely without refresh.

Memory Capacity Calculation

memory-capacity-calc
// Formula: Total capacity = 2^(address lines) Γ— data width

// Example 1: 12 address lines, 8 data lines
Memory locations = 2ΒΉΒ² = 4096 = 4K locations
Data width       = 8 bits = 1 byte
Total capacity   = 4K Γ— 8 bits = 4 KB

// Example 2: How many address lines for 64KB memory with 8-bit data?
64KB = 64 Γ— 1024 = 65536 locations = 2¹⁢
Address lines needed = 16

// Example 3: 16 address lines, 16-bit data bus
Locations = 2¹⁢ = 64K = 65536 locations
Word size = 16 bits = 2 bytes
Total     = 64K Γ— 16 bits = 64K Γ— 2 bytes = 128 KB

// Standard prefixes:
1 KB = 2¹⁰ = 1024 bytes
1 MB = 2²⁰ = 1,048,576 bytes
1 GB = 2³⁰ = 1,073,741,824 bytes
Memory Chip Organization Memory chips are described as "m Γ— n" where m = number of locations and n = bits per location. For example, a "1K Γ— 4" chip has 1024 locations each storing 4 bits. To build an 8-bit-wide memory from 4-bit chips, you need 2 chips in parallel. To double the capacity, you need more chips with additional address decoding.
Practice

Digital Logic Quiz 🎯

Test your exam preparation with these in-depth questions covering all 10 chapters!