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

The 74181 ALU: a 4-bit arithmetic logic unit, live

The 74181 is a 4-bit arithmetic logic unit chip: from two 4-bit words A and B it computes one of 16 logic functions or 16 arithmetic operations, chosen by four select inputs S3 to S0 and a mode input M (M = 1 for logic, M = 0 for arithmetic), with a carry in Cn, a carry out Cn+4 and an A=B output. This live circuit reproduces its function table with logic gates.

The trick inside the chip is that each bit forms two terms, both chosen by S: an OR term P = A + B S0 + B' S1 and an AND term G = A (B' S2 + B S3). In arithmetic mode the chip adds them, F = P plus G plus the carry; in logic mode it blocks the carries and outputs F = NOT (P XOR G). Every row of the table falls out of that. With S = 1001, P = A OR B and G = A AND B, and (A OR B) plus (A AND B) is A plus B, so it adds; with S = 0110, P = A OR NOT B and G = A AND NOT B, which sum to A plus NOT B, that is A minus B minus 1, so it subtracts (a carry in makes it A minus B). The same two S settings in logic mode give XNOR and XOR. TI's datasheet describes the chip as having "a complexity of 75 equivalent gates"; this version uses 61 gates (two-input gates and inverters) and a ripple carry where the chip has carry look-ahead, which changes the speed of real hardware but not the outputs. It leaves out the X and Y look-ahead outputs, which matter only when cascading with a 74182. The datasheet gives two readings of the same pins, and this page uses its Table 2, for active-high data, in which the carries are active low: Cn = 1 means no carry in, Cn = 0 adds 1, and Cn+4 = 0 means a carry out. Before the page is built, all 16 functions in both modes with both carry inputs are checked on 20 pairs of A and B (1,280 rows) against that table, and the full 16,384-row table was checked once. The live circuit opens in A plus B (S = 1001, M = 0, Cn = 1). For the ALU this site's course builds, see the 4-bit ALU and the 1-bit ALU slice.

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 the inputs A3 to A0, B3 to B0, S3 to S0, M and Cn, and probes F3 to F0, Cn+4 and A=B.
  2. For each bit, build the OR term P = A + B S0 + B' S1 and the AND term G = A (B' S2 + B S3).
  3. Add them: the half sum is P XOR G, and the carry into the next bit is G + P c, starting from c0 = NOT Cn.
  4. Form each output as F = (P XOR G) XOR (M OR c): in arithmetic mode the carries add in, and with M = 1 the result is NOT (P XOR G).
  5. Finish with Cn+4 = NOT c4 and A=B = F3 F2 F1 F0. Try A plus B (S = 1001, M = 0, Cn = 1): 0101 and 0011 give F = 1000. Then set S = 0110 and Cn = 0 for A minus B.

74181 function table (active-high data)

S3 S2 S1 S0Logic, M = 1Arithmetic, Cn = 1 (no carry)Arithmetic, Cn = 0 (with carry)
0 0 0 0NOT AAA plus 1
0 0 0 1NOT (A OR B)A OR B(A OR B) plus 1
0 0 1 0(NOT A) AND BA OR (NOT B)(A OR NOT B) plus 1
0 0 1 10minus 1 (1111)0
0 1 0 0NOT (A AND B)A plus (A AND NOT B)A plus (A AND NOT B) plus 1
0 1 0 1NOT B(A OR B) plus (A AND NOT B)(A OR B) plus (A AND NOT B) plus 1
0 1 1 0A XOR BA minus B minus 1A minus B
0 1 1 1A AND (NOT B)(A AND NOT B) minus 1A AND (NOT B)
1 0 0 0(NOT A) OR BA plus (A AND B)A plus (A AND B) plus 1
1 0 0 1NOT (A XOR B)A plus BA plus B plus 1
1 0 1 0B(A OR NOT B) plus (A AND B)(A OR NOT B) plus (A AND B) plus 1
1 0 1 1A AND B(A AND B) minus 1A AND B
1 1 0 01A plus A (shift left)A plus A plus 1
1 1 0 1A OR (NOT B)(A OR B) plus A(A OR B) plus A plus 1
1 1 1 0A OR B(A OR NOT B) plus A(A OR NOT B) plus A plus 1
1 1 1 1AA minus 1A

74181 pinout

PinNamePinName
1B013F3
2A014A=B (open collector)
3S315X (P, look-ahead)
4S216Cn+4
5S117Y (G, look-ahead)
6S018B3
7Cn19A3
8M20B2
9F021A2
10F122B1
11F223A1
12GND24VCC

"plus" and "minus" are 4-bit arithmetic (results wrap around at 16, with the carry on Cn+4), while AND, OR, NOT and XOR act bit by bit. The table and the 24-pin DIP pinout are from TI's SN54LS181/SN74LS181 datasheet (SDLS136), Table 2 and the active-high pin designations, checked 2026-10-25. In Table 1, for active-low data, the same pins are read inverted, which is why the chip's diagrams label the data pins A-bar, B-bar and F-bar.

You can also read the full theory in the lesson on the ALU. 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 subtractorCMOS 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 chip

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 74181 ALU in the lab →

Frequently asked

What does the 74181 do?

It is a 4-bit ALU on one chip. Given two 4-bit numbers A and B, it computes one of 16 logic functions (with M = 1) or one of 16 arithmetic operations, including addition, subtraction, decrement and straight transfer (with M = 0), chosen by the select inputs S3 to S0, and it has a carry in, a carry out and an A=B output.

What is the M input on the 74181?

The mode control. With M high the internal carries are disabled and the chip performs the 16 bitwise logic functions; with M low the carries are enabled and it performs arithmetic.

How does the 74181 subtract?

With S = 0110 in arithmetic mode it adds A to the one's complement of B, which gives A minus B minus 1. Supplying a carry in (Cn = 0 with active-high data) adds the missing 1, so the result is A minus B.

Why are the 74181's carries active low?

The datasheet gives two equivalent readings of the pins. Read with active-low data (Table 1) the carries are active high; read with active-high data (Table 2), as on this page, the carry in and carry out pins are active low: Cn = 0 means a carry in and Cn+4 = 0 means a carry out.

What is the A=B output on the 74181?

It is high when all four F outputs are high. In subtract mode with no carry in, F = A minus B minus 1, which is 1111 exactly when A equals B, so the output works as an equality comparator. On the real chip it is open collector, so several chips' outputs can be wired together for wider words.

How do you build an 8-bit ALU from 74181s?

Use two chips side by side, with the low nibble in one and the high nibble in the other, and connect the carry out Cn+4 of the low chip to the carry in Cn of the high chip. For more chips and higher speed, the 74182 look-ahead carry generator uses each chip's X and Y outputs instead of rippling the carry.