Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

7485 (74LS85): the 4-bit magnitude comparator chip, live

The 7485 compares two 4-bit numbers, A3 to A0 and B3 to B0, and raises one of three outputs: A greater than B, A less than B, or A equal to B. Three cascade inputs carry in the result from a chip handling lower bits, so 7485s chain to compare 8, 12 or more bits. The 74LS85 has the same pinout. This live circuit is the whole chip.

TI's datasheet says it plainly: "These four-bit magnitude comparators perform comparison of straight binary and straight BCD (8-4-2-1) codes. Three fully decoded decisions about two 4-bit words (A, B) are made and are externally available at three outputs." The comparison runs from the top bit down, like the 4-bit magnitude comparator: if A3 and B3 differ they decide, otherwise A2 and B2, and so on. Only when all four bits are equal do the cascade inputs matter, and then the chip passes on the decision of the chip below it: for a longer word, the A>B, A<B and A=B outputs of the stage with the less significant bits go to the matching inputs of the next stage, and the datasheet asks for a high level on the A=B input of the lowest stage. This circuit is built from the datasheet's function table, including its two odd rows: with the words equal and both A>B in and A<B in high, every output is low, and with all three cascade inputs low, A>B out and A<B out are both high. The live chip opens with A = B = 0000 and A=B in high, so A=B out is lit; change any A or B bit. All 2,048 combinations of the eight data inputs and three cascade inputs are checked before the page is built.

Big circuit: pinch, scroll or tap + to zoom in, then drag to move around.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place inputs A3 to A0, B3 to B0, A>Bin, A<Bin and A=Bin, and probes A>Bout, A<Bout and A=Bout.
  2. For each bit, build Ai XNOR Bi (equal), Ai AND NOT Bi (A bigger) and NOT Ai AND Bi (B bigger).
  3. A > B if bit 3 says so, or bit 3 is equal and bit 2 says so, and so on down; the same for A < B. A = B when all four bits are equal.
  4. When A = B, let the cascade inputs decide: A>Bout = NOT A<Bin AND NOT A=Bin, A<Bout = NOT A>Bin AND NOT A=Bin, A=Bout = A=Bin. For one chip, tie A=Bin high.

7485 function table

A and BA>B inA<B inA=B inA>B outA<B outA=B out
A > BXXX100
A < BXXX010
A = B100100
A = B010010
A = BXX1001
A = B110000
A = B000110

7485 pinout

PinNamePinName
1B316VCC
2A<B in15A3
3A=B in14B2
4A>B in13A2
5A>B out12A1
6A=B out11B1
7A<B out10A0
8GND9B0

X means the input does not matter; A > B or A < B means the four data bits already decide. The function table and the 16-pin pinout are from TI's SN7485 / SN74LS85 datasheet (SDLS123), checked 2026-10-25. For a single chip, or the lowest chip of a chain, tie A=B in high: then the other two cascade inputs do not matter.

You can also read the full theory in the lesson on comparators. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

Build more parts from gates

half adderfull adderhalf subtractorfull subtractor2:1 multiplexer4:1 multiplexerXOR gate from NAND gates2-to-4 decoderSR latchD flip-flopJK flip-flopT flip-flop4-bit shift register4-bit ripple carry adderD latch1-to-4 demultiplexer4-bit magnitude comparator4-bit ring counter4-bit Johnson counter4-to-2 priority encoder4-bit synchronous counter3-to-8 decoder8-to-1 multiplexer4-bit carry lookahead adderhalf adder from NAND gates2-bit comparatorBCD to 7-segment decoder4-bit up/down counterdecade counter2-bit multiplier4-bit ALU4-bit array multiplierNOT, AND, OR and NOR from NANDNOT, OR, AND and XOR from NORfull adder from NAND gatesSR latch from NAND gatesparity generator and checker4-bit adder/subtractorBCD adder4-bit universal shift registermod-6 counter4-bit ripple counterbinary to Gray code converterhalf adder from NOR gatesfull adder from NOR gates4-bit register with parallel load1011 sequence detectorbinary to BCD converterD flip-flop from NAND gates1-bit ALUCMOS inverterCMOS NAND gateCMOS NOR gatePISO shift registerSR flip-flop from NAND gatesBCD to excess-3 code converterHamming (7,4) code encoder and correctortraffic light controller4-bit barrel shifterCMOS AND gateCMOS OR gateCMOS XOR gate1-bit magnitude comparatorhalf subtractor from NAND gatesfull subtractor from NAND gates8-to-3 encoderGray to binary converter4-to-16 decoderfull adder using 4:1 multiplexersedge detectorserial adder4-bit carry-select adder4-bit Kogge-Stone adder4-bit carry-skip adder4x4 Wallace tree multiplier8-bit adderfrequency divider (by 2, 4 and 3)switch debouncer (SR latch)3-bit Gray code counterMealy machine (1011 detector)master-slave JK flip-flop (NAND)half subtractor from NOR gates1-to-8 demultiplexerexcess-3 to BCD code convertervending machine FSM4-bit carry-save adder3-bit synchronous counter (JK)CMOS transmission gatetri-state buffer (CMOS)2-to-1 mux from transmission gatesmod-5 counterflip-flop conversion (JK to D)8-bit ALUdecimal to BCD encoderBCD to decimal decoder4-to-1 mux from 2-to-1 muxesXOR gate from NOR gates4-bit LFSR74LS138 decoderBCD subtractor74181 ALUCMOS AOI gate (AOI21)D latch vs D flip-flop74LS47 BCD to 7-segment decoder74HC595 shift register7400 quad NAND gate chip7402 quad NOR gate chip7404 hex inverter chip7408 quad AND gate chip7432 quad OR gate chip7486 quad XOR gate chip7474 dual D flip-flop74HC165 shift registerCD4017 decade counter74LS283 4-bit adder74LS90 decade counter74HC161 4-bit counter74HC151 8-to-1 multiplexer74HC157 quad 2-to-1 multiplexer74HC139 dual 2-to-4 decoderCD4511 BCD to 7-segment decoder7492 divide-by-12 counter7493 4-bit binary counter74HC244 octal bufferRace-around condition (JK latch)74HC373 octal latch74HC374 octal D flip-flopTurnstile state machine1-to-2 demultiplexerhalf adder using 2:1 multiplexersregister file (4 x 4-bit)digital PWM generatorCD4013 dual D flip-flop74LS76 dual JK flip-flop7410 triple 3-input NAND chip7411 triple 3-input AND chip7420 dual 4-input NAND chipCD4011 quad 2-input NAND chipCD4001 quad 2-input NOR chipCD4081 quad 2-input AND chipCD4069 hex inverter chip74HC164 8-bit shift register74HC125 quad tri-state buffer

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the 7485 4-bit magnitude comparator in the lab →

Frequently asked

What does the 7485 do?

It compares two 4-bit binary numbers, A and B, and sets exactly one of its outputs A>B, A<B or A=B (for normal cascade inputs). Three cascade inputs let several 7485s compare longer numbers.

How do you cascade two 7485 comparators?

Wire the A>B, A<B and A=B outputs of the chip comparing the lower 4 bits to the A>B, A<B and A=B inputs of the chip comparing the upper 4 bits, and tie the lower chip's A=B input high. The upper chip's outputs then compare all 8 bits.

What is the 7485 pinout?

Pin 1 B3, 2 A<B in, 3 A=B in, 4 A>B in, 5 A>B out, 6 A=B out, 7 A<B out, 8 GND, 9 B0, 10 A0, 11 B1, 12 A1, 13 A2, 14 B2, 15 A3, 16 VCC.

Can the 7485 compare BCD numbers?

Yes. TI's datasheet says it compares straight binary and straight BCD (8-4-2-1) codes: a BCD digit is just a 4-bit binary number from 0 to 9.