Binary Subtraction Calculator
Subtract binary numbers with step-by-step borrow visualization. Supports arbitrary-length binary, two's complement, and decimal conversion.
About
Binary subtraction is the foundation of arithmetic logic units in every processor. Errors in manual binary subtraction propagate through borrow chains - a single mishandled borrow bit corrupts every subsequent column. This calculator performs exact subtraction on arbitrary-length binary strings using the column-by-column borrow method, the same algorithm implemented in hardware ripple-borrow subtractors. It displays every intermediate borrow so you can audit each step. Results include the decimal equivalent and two's complement representation for standard bit widths (8, 16, 32 bits).
The tool assumes unsigned binary input by default. When the subtrahend exceeds the minuend, the result is flagged negative and the magnitude is computed as B β A. Two's complement output is provided for signed interpretation at fixed widths. Note: leading zeros are preserved in step display but stripped from the final result. Pro tip: if you are debugging ALU designs or verifying homework, cross-check the borrow row against your carry chain - they must mirror each other in subtraction-by-complement methods.
Formulas
Binary subtraction operates column-by-column from the least significant bit (rightmost) to the most significant bit, propagating borrows leftward. For each column i:
Two's complement for an n-bit negative result βM:
Which is equivalent to inverting all bits and adding 1.
Where ai = bit i of minuend, bi = bit i of subtrahend, borrowi = incoming borrow at column i, diffi = result bit at column i, n = bit width for two's complement, M = magnitude of the result.
Reference Data
| Bit Width | Unsigned Range | Signed Range (Two's Complement) | Max Decimal | Min Signed Decimal | Overflow Threshold |
|---|---|---|---|---|---|
| 4 bits | 0 - 15 | β8 - 7 | 15 | β8 | 11112 |
| 8 bits | 0 - 255 | β128 - 127 | 255 | β128 | 111111112 |
| 16 bits | 0 - 65535 | β32768 - 32767 | 65535 | β32768 | 11111111111111112 |
| 32 bits | 0 - 4294967295 | β2147483648 - 2147483647 | 4294967295 | β2147483648 | 32 ones |
| 64 bits | 0 - 1.844 Γ 1019 | β9.22 Γ 1018 - 9.22 Γ 1018 | 1.844 Γ 1019 | β9.22 Γ 1018 | 64 ones |
| Common Binary Subtraction Patterns | |||||
| 102 β 12 | = 12 | Borrow: none | |||
| 102 β 102 | = 02 | Borrow: none | |||
| 1002 β 12 | = 112 | Borrow chain: 2 columns | |||
| 10002 β 12 | = 1112 | Borrow chain: 3 columns | |||
| 100002 β 12 | = 11112 | Borrow chain: 4 columns | |||
| 10102 β 01112 | = 112 | Borrow at columns 0, 1, 2 | |||
| 111111112 β 12 | = 111111102 | Borrow: none | |||
| 111111112 β 111111112 | = 02 | Borrow: none | |||