
Video: Subtraction | Logical Redstone #12 by mattbatwings
How to build it
- Set Up a 4-Bit Binary Adder
Start with a working 4-bit binary adder (such as a Carry Cancel Adder). Designate the most significant bit (the 4th bit) on both inputs and the output as the sign bit—0 for positive numbers and 1 for negative numbers.
- Invert the B Inputs (Permanent Subtractor)
To subtract B from A (A + negative B), move the input levers for the B side back by a couple of blocks. Place a Redstone Torch on the back of each B input block so every bit of B is inverted before entering the adder.
- Power the Carry-In Line
Locate the Carry-In input on the least significant bit (1s place) of your adder. Power this line permanently with a lever or Redstone Torch to add 1 to the inverted B input, completing the two's complement conversion.
- Build XOR Gates on the B Inputs (Toggleable Version)
If you want your machine to switch between adding and subtracting, remove the simple inverters from Step 2. Instead, build an XOR gate in front of each bit of the B input so the B levers feed into one side of each XOR gate.
- Connect the Subtract Control Line
Run a shared Redstone line connected to a master 'Subtract' lever into the second input of all four XOR gates on the B side. When this line is off, B passes through unchanged; when on, every bit of B is inverted.
- Link the Control Line to Carry-In
Branch the same master 'Subtract' lever line over to the adder's Carry-In input. Now, flipping the master lever ON simultaneously inverts all bits of B and adds 1 via Carry-In, turning your adder into a subtractor.
How it works
This circuit relies on Two's Complement representation, which allows binary adders to handle negative numbers without separate subtraction hardware:
- Sign Bit: In a 4-bit system, the top bit (normally worth 8) acts as the sign bit. A
0indicates a positive number (ranging from 0 to +7), and a1indicates a negative number. - Multiplying by -1: To turn a positive binary number into its negative counterpart, you perform two steps: invert all the bits (flip
0s to1s and1s to0s) and add1to the result. For example, +5 (0101) inverted becomes1010, and adding 1 yields1011(-5). - A - B as A + (-B): By placing Redstone Torches on the B input lines, the circuit automatically inverts B. By turning on the adder's Carry-In line on the first bit, the circuit adds
1. Together, the adder calculatesA + (~B + 1), which equalsA - B. - Controlled Inversion with XORs: In the toggleable version, an XOR gate outputs
1only when its inputs differ. Feeding the control line into one side of the XOR means that when the control is0, the B bit passes through normally (B XOR 0 = B). When the control is1, the XOR acts as an inverter (B XOR 1 = NOT B) while also powering the Carry-In.
Tips & variations
- Watch for Overflow: With 4 bits in two's complement, one bit is reserved for the sign, meaning the maximum positive number you can represent is
+7(0111). Adding5 + 3will overflow into the sign bit (1000) and read as a negative number. Expand your adder to 8 bits if you need larger numbers. - Consistent Bit Width: Always pad smaller numbers with leading zeros up to your full bit width before inverting them, otherwise the sign bit will not flip properly.
- Reading Negative Outputs: Negative outputs in two's complement do not look like standard binary magnitudes (e.g.,
1101is -3). To verify a negative output by hand, invert all its bits and add 1 to reveal its positive magnitude.





