Hardware almost never subtracts directly. It uses the identity A − B = A + (−B), and in twos complement, −B is easy to make: invert B and add 1. So:
A − B = A + B' + 1, where B' is B with every bit inverted.
By hand:
- Write both numbers at the same width.
- Invert every bit of B.
- Add A, the inverted B, and 1.
- Drop any carry out beyond the width.
The resulting bits are right whether you read them as unsigned or signed. What changes is how you check the answer:
- Unsigned: carry-out 1 means no borrow, so A ≥ B. Carry-out 0 means A < B, and the result has wrapped around.
- Signed: apply the signed overflow rule to A and −B, or use V = Cₙ ⊕ Cₙ₋₁.
In a circuit, the adder subtractor does this with a row of XOR controlled inverters on B, plus the carry-in C0 = 1 for the +1.