Components / Arithmetic
Comparator Component in Logisim
Compares two N-bit signed integers A and B and asserts exactly one of its three 1-bit outputs: A>B, A=B, or A<B.
| Library | Arithmetic |
|---|---|
| Type name | Comparator |
| Pins and defaults | a A (-40, -10), b B (-40, 10), gt A>B (0, -10), eq A=B (0, 0), lt A<B (0, 10), width 4 (1..32) |
How the Comparator Works in Logisim
The Comparator evaluates the relative magnitude of two N-bit two's complement signed integers A and B (default width = 4 bits). On its right edge, it provides three mutually exclusive 1-bit outputs from top to bottom: A>B (gt), A=B (eq), and A<B (lt).
Whenever both A and B are fully defined, exactly one of the three outputs is 1 and the other two are 0. If any bit of A or B is floating (Z) or in conflict (E), all three comparison outputs become E.
Tip: Note that the Comparator uses signed two's complement ordering (for 4-bit inputs, 0b1111 is -1, which is less than 0b0001 = +1).
Comparator Pins & Pinout
| Pin | Direction | Width | Location & Role |
|---|---|---|---|
| a (A) | Input (Upper-left) | 1–32 bits (default 4) | Offset (-40, -10). First signed operand A. |
| b (B) | Input (Lower-left) | 1–32 bits (default 4) | Offset (-40, 10). Second signed operand B. |
| gt (A>B) | Output (Upper-right) | 1 bit | Offset (0, -10). Outputs 1 when A > B (signed two's complement). |
| eq (A=B) | Output (Middle-right) | 1 bit | Offset (0, 0). Outputs 1 when A = B. |
| lt (A<B) | Output (Lower-right) | 1 bit | Offset (0, 10). Outputs 1 when A < B (signed two's complement). |
Comparator Truth Table & Behavior
| Condition | gt (A>B) | eq (A=B) | lt (A<B) |
|---|---|---|---|
| A > B | 1 | 0 | 0 |
| A = B | 0 | 1 | 0 |
| A < B | 0 | 0 | 1 |
| A or B has Z / E | E | E | E |