DIGITAL LOGIC MASTER GUIDE · MAGNITUDE COMPARATOR

ARITHMETIC & COMPARISON CIRCUITS

Digital Magnitude Comparators (1-bit, 2-bit & IC 74LS85)

A Digital Magnitude Comparator is a combinational logic circuit that compares two binary numbers, A and B, and determines their relative magnitude by evaluating whether A > B, A = B, or A < B.

▲ Output 1: A > B (A is Greater than B) ■ Output 2: A = B (A is Equal to B) ▼ Output 3: A < B (A is Less than B)
Core Principle: The three outputs are mutually exclusive. For any given pair of binary inputs (A and B), exactly one output will be HIGH (1), and the other two will be LOW (0).

Figure 1: General Block Diagram of an n-Bit Magnitude Comparator

n-Bit Magnitude Comparator Input A [Aₙ₋₁ ... A₀] Input B [Bₙ₋₁ ... B₀] A > B A = B A < B

1. 1-Bit Magnitude Comparator

A 1-bit magnitude comparator compares two single binary digits, A and B. Since each input has 2 possible values (0 or 1), there are \(2^2 = 4\) total combinations.

Truth Table of 1-Bit Comparator

Input A Input B A > B A = B A < B
00 010
01 001
10 100
11 010

Boolean Equations & Derivations

1. Greater Than: A > B = A · B̅
(True only when A = 1 AND B = 0)
2. Equality: A = B = A̅·B̅ + A·B = A ⊙ B
(XNOR Gate acts as the coincidence equality detector)
3. Less Than: A < B = A̅ · B
(True only when A = 0 AND B = 1)

Figure 2: Complete Logic Gate Schematic for 1-Bit Comparator

A B A̅ B̅ AND A > B = A · B̅ XNOR A = B = A ⊙ B AND A < B = A̅ · B

2. 2-Bit Magnitude Comparator

A 2-bit comparator compares two 2-bit words: A = (A₁A₀) and B = (B₁B₀), representing decimal values from 0 to 3.

Hierarchical Multi-Bit Comparison Logic:

Step 1 Compare MSBs (A₁ vs B₁):
• If A₁ > B₁ (i.e. A₁=1, B₁=0), then A > B regardless of A₀ and B₀.
• If A₁ < B₁ (i.e. A₁=0, B₁=1), then A < B regardless of A₀ and B₀.

Step 2 If MSBs are Equal (A₁ = B₁):
Let the bit-1 equality flag be x₁ = A₁ ⊙ B₁. If x₁ = 1, compare LSBs:
• If A₀ > B₀ (A₀=1, B₀=0), then A > B.
• If A₀ < B₀ (A₀=0, B₀=1), then A < B.

Step 3 Overall Equality:
If both bit positions are identical: A = B = x₁ · x₀.

Complete 16-Row Truth Table

Input A Input B Dec A Dec B A > B A = B A < B
A₁A₀ B₁B₀
000000010
000101001
001002001
001103001
010010100
010111010
011012001
011113001
100020100
100121100
101022010
101123001
110030100
110131100
111032100
111133010

K-Map Simplifications (With Cell Minterms & Groupings)

K-Map for A > B

B₁B₀A₁A₀ 00011110
00 m00 m10 m30 m20
01 m41 m50 m70 m60
11 m121 m131 m150 m141
10 m81 m91 m110 m100
Quad Group: A₁·B₁̅ Pair Group: x₁·(A₀·B₀̅)
A > B = A₁·B₁̅ + x₁·(A₀·B₀̅)

K-Map for A < B

B₁B₀A₁A₀ 00011110
00 m00 m11 m31 m21
01 m40 m50 m71 m61
11 m120 m130 m150 m140
10 m80 m90 m111 m100
Quad Group: A₁̅·B₁ Pair Group: x₁·(A₀̅·B₀)
A < B = A₁̅·B₁ + x₁·(A₀̅·B₀)
Bit Equality Flags:
Let x₁ = A₁ ⊙ B₁ = A₁̅·B₁̅ + A₁·B₁ (MSB equality detector)
Let x₀ = A₀ ⊙ B₀ = A₀̅·B₀̅ + A₀·B₀ (LSB equality detector)

1. Equality Condition: A = B = x₁ · x₀
2. Greater Than Condition: A > B = A₁·B₁̅ + x₁·(A₀·B₀̅)
3. Less Than Condition: A < B = A₁̅·B₁ + x₁·(A₀̅·B₀)

Figure 3: Complete Logic Gate Schematic of 2-Bit Magnitude Comparator

A₁ B₁ A₀ B₀ XNOR₁ x₁ XNOR₀ x₀ A = B (x₁·x₀) OR A > B OR A < B

3. 4-Bit Magnitude Comparator (IC 74LS85)

The IC 74LS85 is the standard monolithic 4-bit magnitude comparator in a 16-pin DIP package. It compares two 4-bit nibbles: A = (A₃, A₂, A₁, A₀) and B = (B₃, B₂, B₁, B₀).

IC 74LS85 Hardware Pinout (DIP-16)

              IC 74LS85 DIP-16
               .-----\_/-----.
 (Bit 3)   B3 | 1        16 | VCC (+5V Power)
 (Cascade) IAB | 4        13 | A2 (Bit 2)
 (Output)  OA>B | 5        12 | A1 (Bit 1)
 (Output)  OA=B | 6        11 | B1 (Bit 1)
 (Output)  OA
          

Internal Bit-by-Bit Logic Equations

Let xᵢ = Aᵢ ⊙ Bᵢ represent equality at bit position i ∈ {0, 1, 2, 3}:

1. Equality Output: OA=B = x₃ · x₂ · x₁ · x₀ · (IA=B)
2. Greater Output: OA>B = A₃·B₃̅ + x₃(A₂·B₂̅) + x₃x₂(A₁·B₁̅) + x₃x₂x₁(A₀·B₀̅) + (x₃x₂x₁x₀ · IA>B)
3. Less Output: OA<B = A₃̅·B₃ + x₃(A₂̅·B₂) + x₃x₂(A₁̅·B₁) + x₃x₂x₁(A₀̅·B₀) + (x₃x₂x₁x₀ · IA<B)

4. Multi-Stage Cascading (Building 8-Bit & 16-Bit Comparators)

When comparing words wider than 4 bits (e.g., 8-bit bytes or 16-bit integers), multiple 74LS85 ICs are connected in cascade.

Figure 4: 8-Bit Comparator Cascading Architecture (2 x IC 74LS85)

IC 1: 74LS85 (Lower Nibble) Inputs: A₃..A₀ & B₃..B₀ IA=B = +5V (VCC / HIGH) IA>B = 0V (GND / LOW) IA<B = 0V (GND / LOW) OA>B → IA>B OA=B → IA=B OA<B → IA<B IC 2: 74LS85 (Upper Nibble) Inputs: A₇..A₄ & B₇..B₄ A > B A = B A < B
Golden Cascading Rules:
  1. Least Significant Stage (IC 1): Tie IA=B to VCC (+5V / Logic 1) and tie IA>B and IA<B to GND (0V / Logic 0).
  2. Cascade Linkage: Outputs of IC 1 (\(OA>B, OA=B, OAB, IA=B, IA
  3. Final Decision: Outputs of the Most Significant Stage (IC 2) provide the authoritative final comparison results.

5. Worked Step-by-Step Examples

Example 1 4-Bit Comparison

Compare A = 1101₂ (13₁₀) and B = 1100₂ (12₁₀):

  • Bit 3: A₃ = 1, B₃ = 1 → Equal (x₃ = 1). Proceed to Bit 2.
  • Bit 2: A₂ = 1, B₂ = 1 → Equal (x₂ = 1). Proceed to Bit 1.
  • Bit 1: A₁ = 0, B₁ = 0 → Equal (x₁ = 1). Proceed to Bit 0.
  • Bit 0: A₀ = 1, B₀ = 0 → A₀ > B₀!
  • Result: Output A > B = 1 (A=B is 0, A<B is 0).

Example 2 4-Bit Comparison

Compare A = 0110₂ (6₁₀) and B = 1000₂ (8₁₀):

  • Bit 3 (MSB): A₃ = 0, B₃ = 1.
  • Since A₃ < B₃ at the MSB, lower bits (Bits 2, 1, 0) do not need to be evaluated.
  • Result: Output A < B = 1 immediately!

6. Real-World Applications of Digital Comparators

1. CPU Arithmetic & Logic Units

Used in microprocessors to execute comparison instructions (like CMP in x86/ARM) and generate conditional jump flags (Zero flag ZF, Sign flag SF).

2. Digital Thermostats & Controls

Compares sensor-measured room temperature against the target setpoint to automatically switch heaters or air conditioners on/off.

3. Flash ADC Converters

High-speed analog-to-digital converters use banks of voltage comparators to instantaneously quantize analog signals into digital binary values.