1101 − 0110 — binary arithmetic

introborrowing across a zero

Answer

0111

Why this example is worth doing

Direct binary subtraction with borrows, which most courses teach before the two's complement method. The awkward case is borrowing across a 0, where the borrow propagates further left, and the tool shows the modified digits above the minuend. The page then shows the same subtraction done by adding the two's complement, so the two methods can be compared on one problem rather than in separate chapters.

Try your own input in the Binary arithmetic. Add, subtract, multiply and divide in binary with every carry and borrow shown.

How the answer is reached

1101 - 0110 (4-bit, unsigned)

1101 - 0110 (4-bit, unsigned) — columns operand, bits, hex, unsigned, signed
operandbitshexunsignedsigned
A11010xD13-3
B01100x666

Method A — borrow propagation.

The digit above column i is the carry or borrow into column i. Bit 0 is the least significant column. — 1101 - 0110
row3210
borrow in1100
A1101
- B0110
result0111

C = 0 · V = 1 · N = 0 · Z = 0

Method B — add the two’s complement of B, then discard the final carry.

NOT B1001

NOT B + 11010the two’s complement of B

The digit above column i is the carry or borrow into column i. Bit 0 is the least significant column. — 1101 + 1001
row3210
carry in0011
A1101
+ B1001
result0111

carry in 1 · carry out 1 (discarded)

reading the final carry1: no borrow, A >= B as unsigned

signed-3 - 6 = -9, kept as 7V = 1: the signed answer is wrong

Warning:

Both methods are shown because curricula grade different ones. The final carry of method B is always the complement of the borrow-out of method A.

Compare with

Open this example in the Binary arithmetic

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Fractions are converted digit by digit and shown to a stated number of places rather than rounded silently.

Sources

  • Knuth, The Art of Computer Programming, Vol. 2, §4.3.1 “The Classical Algorithms” (1997)