Advertisement

Binary subtraction calculator

Subtract two binary numbers, retain a negative exact answer, and inspect the stored two's complement pattern and column borrows.

Calculator

Exact result in binary
101
Exact decimal result
5
Result stored in selected width
00000101
Stored unsigned decimal
5
Stored signed decimal
5
Exact result exceeds selected range
No
Column steps
PositionLarger bitSmaller bitBorrow inDifference bitBorrow out
001011
101101
200111
310100
400000
500000
600000
700000

Advertisement

How this calculator works

For nonnegative inputs, subtract the smaller magnitude from the larger, borrowing 1 from the next column whenever needed. A borrow contributes two to the current column. The exact result takes the sign of A - B. The borrow table follows those magnitudes. For signed inputs with opposite signs, the table is omitted because subtraction requires addition of magnitudes. Select unsigned or two's complement interpretation before entering patterns. Short inputs are padded with zeros to the selected width; signed negatives therefore need a leading 1 at that width. Overflow describes the exact mathematical answer, which is never silently discarded.

Formula

Difference = A - B. A negative result stores as (A - B) mod 2^n in n bits.

Worked example

1000 - 0011 = 0101, or 8 - 3 = 5. Reversing the operands gives -101, stored as 1011 in four bits.

Advertisement

Frequently asked questions

What does the selected width change?

It limits each operand and determines the stored result and signed interpretation. The exact answer is also displayed, even when it needs more bits.

How are negative inputs entered?

Choose two's complement and enter the complete negative pattern for the chosen width. For example, 11111111 is -1 in eight bits. A minus sign is only accepted in the exact sum field for missing-addend calculations.

Are long binary strings exact?

Yes. Operands are text strings and calculations use integer arithmetic with no rounding. Presets reach 64 bits and custom widths reach 256 bits.

What do the steps show?

The table follows the magnitude calculation described above. Read the exact result for its final sign; stored results wrap to the selected width.

Sources

Advertisement