Borrowing During Binary Subtraction

A binary subtraction column borrows from the next position when its available digit cannot cover the subtrahend and any outstanding borrow.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a borrow chain
  2. Check width and interpretation
  3. Pass each borrow to the next higher column
  4. Decide what the final borrow means for unsigned data

Trace a borrow chain

To subtract one from 1000, borrowing crosses the zero columns. The next three low output positions become one and the former high bit clears. The result 0111 is seven in binary notation.

Check width and interpretation

Subtracting one from 0000 can produce all ones in a wrapping four-bit field. The unsigned value is 15 and the signed two's-complement value is minus one. Two's complement supplies the latter meaning.[1]

Pass each borrow to the next higher column

Subtract 0011 from 1000. The lowest bit needs a borrow. Higher zero positions pass that need along until the highest one supplies it. The result is 0101, matching eight minus three. See adding by columns for the analogous propagation in addition.

Column from right    0 1 2 3
Incoming borrow      0 1 1 1
Difference bit       1 0 1 0
Outgoing borrow      1 1 1 0
Read result high-to-low: 0101

Decide what the final borrow means for unsigned data

With fixed unsigned width, a final borrow means the exact difference was negative. If the operation wraps, the stored bits still represent a nonnegative residue. Test equal operands, a long borrow chain and a subtrahend greater than the minuend.

References

  1. Python Software Foundation, Python Standard Library: Built-in Types ↩