Logo
All chapters
Volume II: Digital Logic  ›  Combinational Logic

Magnitude Comparator

Tells whether A < B, A = B, or A > B for two binary numbers.

PrevBinary Multiplier
NextDecoders

Description

A circuit that orders two numbers (less, equal, greater). Decisions, sorting, and bounds checks all need comparison. XNOR each bit for equality; scan from MSB to find the first difference.

  • A = B when every bit pair is equal (all XNORs are 1).
  • Otherwise the highest differing bit decides: a 1 in A there means A > B.
  • What: A circuit that orders two numbers (less, equal, greater).
  • Why: Decisions, sorting, and bounds checks all need comparison.
  • How: XNOR each bit for equality; scan from MSB to find the first difference.
  • Where: ALUs (condition flags), address-range logic, sort hardware.
  • When: Any branch or selection based on numeric order.
  • A>B = A·B′
  • A<B = A′·B
  • A=B = A⊙B (XNOR)

At a glance

What

A circuit that orders two numbers (less, equal, greater).

Why

Decisions, sorting, and bounds checks all need comparison.

How

XNOR each bit for equality; scan from MSB to find the first difference.

Where

ALUs (condition flags), address-range logic, sort hardware.

When

Any branch or selection based on numeric order.

Think of it like…

Like comparing two phone numbers digit by digit from the left: the first place they differ decides which is bigger — earlier digits outrank later ones.

How it decides

  • A = B when every bit pair is equal (all XNORs are 1).
  • Otherwise the highest differing bit decides: a 1 in A there means A > B.

Outputs

ConditionAsserted output
all bits equalA = B
first diff: A bit = 1A > B
first diff: A bit = 0A < B

Black-box view

AB1-bit Comparatorblack boxA>BA=BA<B

Inputs on the left → outputs on the right · particles show signal direction

Logic diagram

0A>B1A=B0A<BA0B0NOTNOTANDANDXNOR

Click inputs to toggle · glowing wires carry 1 · particles show signal direction

The 5 Whys

  1. 1

    Why a comparator? Programs constantly test order and equality.

  2. 2

    Why scan from the MSB? The most-significant differing bit dominates magnitude.

  3. 3

    Why XNOR for equality? XNOR is 1 exactly when two bits match.

  4. 4

    Why dedicated hardware? Comparison is on the critical path of branches.

  5. 5

    Root cause: ordering reduces to equality plus first-difference detection.

Cheat sheet

Working principle

  • XNOR each bit for equality; scan from MSB to find the first difference.
  • A circuit that orders two numbers (less, equal, greater).

Formulas & Boolean expressions

  • A>B = A·B′
  • A<B = A′·B
  • A=B = A⊙B (XNOR)
  • A = B when every bit pair is equal (all XNORs are 1).
  • all bits equal = A = B
  • first diff: A bit = 1 = A > B
  • first diff: A bit = 0 = A < B

Key facts

  • A = B when every bit pair is equal (all XNORs are 1).

Why it exists

  • Root cause: ordering reduces to equality plus first-difference detection.
PrevBinary Multiplier
NextDecoders