ARITHMETIC LOGIC UNIT
4-Bit Binary Adder / Subtractor
Simulate 4-bit binary addition and 2's complement subtraction using cascaded Full Adders (IC 74LS83). Observe ripple-carry propagation and XOR-gate controlled mode inversion in real time.
Interactive 4-Bit Arithmetic
Mode M = 0: Addition (A + B + Cin). Input B bits enter unchanged.
Input Word A (4 bits)
Decimal: 0
Input Word B (4 bits)
Decimal: 0
Carry-In (Cin / C0)
Toggle initial carry-in for Stage 0 addition. In subtraction, Cin is locked to Mode M = 1 (+1 for 2's complement).
Arithmetic Output: [Carry-Out (2⁴ = 16)] + [4-Bit Sum (S3 S2 S1 S0)]
2⁴ (16)
0
Cout
2³ (8)
0
S3
2² (4)
0
S2
2¹ (2)
0
S1
2⁰ (1)
0
S0
Full Adder Ripple-Carry Stages (LSB to MSB)
| Stage (Bit) | Ai | Bi | Effective Bi (Bi ⊕ M) | Cin | Sum (Si) | Cout |
|---|---|---|---|---|---|---|
| Click "Execute Operation" to compute ripple stages. | ||||||
04
THEORY & IMPLEMENTATION
Adder / Subtractor Architecture (IC 74LS83)
The 2's Complement Hardware Sharing Trick
In computer arithmetic, subtraction is executed using the exact same adder hardware by leveraging two's complement:
A - B = A + (2's complement of B) = A + (B' + 1)
By feeding the mode bit M into an XOR gate with each bit of B, and also connecting M directly to the initial carry-in Cin:
- When M = 0 (Addition): B ⊕ 0 = B (bits unchanged), and Cin = 0. Output is A + B.
- When M = 1 (Subtraction): B ⊕ 1 = B' (bitwise NOT / 1's complement), and Cin = 1 (+1). Output is A + B' + 1 = A - B.
Full Adder Boolean Equations
Sum (Si) = Ai ⊕ Bi ⊕ Cin
Carry-Out (Cout) = (Ai · Bi) + (Cin · (Ai ⊕ Bi))
Carry-Out (Cout) = (Ai · Bi) + (Cin · (Ai ⊕ Bi))