Binary Number Subtractor
Subtract binary numbers online with step-by-step column subtraction, two's complement breakdown, borrow visualization, and instant results.
About
Binary subtraction is the arithmetic foundation of every ALU (Arithmetic Logic Unit) in modern processors. Hardware does not subtract directly. It converts the subtrahend B into its two's complement and performs addition. Misunderstanding borrow propagation or sign handling leads to off-by-one errors in firmware, FPGA netlists, and low-level protocol implementations. This tool computes A − B for arbitrary-length unsigned binary strings using both the column-borrow method and the two's complement method, exposing every intermediate step. Results are cross-verified. The tool assumes unsigned interpretation. When B > A, the magnitude |A − B| is computed and flagged negative. Precision is limited only by browser string length, not by 32-bit or 64-bit word boundaries.
Formulas
Column subtraction at bit position i with borrow:
Two's complement method:
Where A is the minuend (first operand), B is the subtrahend (second operand), ⊕ is XOR, ¬ is bitwise NOT, and borrowi is the incoming borrow at position i (LSB → MSB).
Reference Data
| Bit A | Bit B | Borrow In | Difference | Borrow Out |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |