
Video: Redstone Binary Subtraction - LRR #5 by mattbatwings
How to build it
- Set Up a Multi-Bit Binary Adder
Start with a working binary adder (such as a 4-bit Carry Cancel Adder) that has two multi-bit inputs (A and B), a Carry-In line on the first bit, and output lamps.
- Prepare the B Input Lines
Clear some space along the B input wires before they enter the adder. Leave the A input wires untouched, as only the B number needs to be negated for A - B.
- Build an XOR Gate on Each B Bit
Insert an XOR gate inline with each bit of the B input. Connect each B input lever into one input of its corresponding XOR gate, and run the XOR gate's output directly into the adder's B input.
- Wire the Shared Control Tower
Connect the second input of every XOR gate on the B lines together into a vertical redstone tower or shared bus line so they all receive the exact same control signal.
- Link the Control Signal to Carry-In
Run a redstone line from that same shared XOR control line directly into the Carry-In input of the adder's least significant bit (the 1s place).
- Add the Mode Toggle Lever
Place a single control lever powering the shared control line. Leave it OFF for addition mode, or flip it ON to invert B and add 1 for subtraction mode.
- Test Addition and Subtraction
Input 5 (0101) on A and 2 (0010) on B. With the mode lever OFF, the output reads 7 (0111); flip the mode lever ON and the output switches to 3 (0011).
How it works
This circuit works by converting subtraction into addition using Two's Complement binary notation, where subtracting A - B is equivalent to calculating A + (-B).
- Two's Complement Negation: In an N-bit binary system (modulo 2N), you can negate any number by inverting all of its bits (0 becomes 1, 1 becomes 0) and adding 1.
- Conditional Inverter (XOR Gates): An XOR gate acts as a toggleable inverter. When the control input is
0(Addition mode), the B input bits pass straight through unchanged. When the control input is1(Subtraction mode), every bit of the B input is inverted (creating the One's Complement of B). - Carry-In Adds 1: Because the mode control lever is also wired to the adder's Carry-In line, turning on Subtraction mode simultaneously adds
1to the least significant bit. - Ignoring Overflow: When the two numbers are added, any carry-out beyond the final bit (e.g., the 16s place in a 4-bit adder) is discarded, wrapping the result around in modular arithmetic to yield the exact difference.
Tips & variations
- Fixed Subtractor Variant: If you only ever need subtraction and don't need to toggle back to addition, replace the XOR gates on the B inputs with simple Redstone Torches (NOT gates) and permanently power the Carry-In line.
- Watch Your Number Range: In 4-bit Two's Complement, the valid signed range is only
-8to+7. Notice that the highest bit acts as the sign bit (0for positive,1for negative, equivalent to a-8place value). Adding or subtracting past this range causes an overflow error. - Prevent Signal Delay Mismatches: When stacking vertical XOR gates for the B inputs, make sure the control tower powers all bits evenly and repeaters don't accidentally back-feed into adjacent bit lines.





