1011 + 1101 — binary arithmetic

introcarries through every column

Answer

11000

Why this example is worth doing

Binary addition with a carry out of almost every column, which is the case worth starting on because the carry chain is the whole difficulty. The rules are four lines long — 0+0, 0+1, 1+0, and 1+1 which gives 0 carry 1 — and the tool draws the carry row above the operands exactly as it is done by hand. Eleven plus thirteen is twenty-four, and the decimal check is printed alongside.

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

01011 + 01101 (5-bit, unsigned)

01011 + 01101 (5-bit, unsigned) — columns operand, bits, hex, unsigned, signed
operandbitshexunsignedsigned
A010110x0B1111
B011010x0D1313
The digit above column i is the carry or borrow into column i. Bit 0 is the least significant column. — 01011 + 01101
row43210
carry in11110
A01011
+ B01101
result11000

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

unsigned11 + 13 = 24, kept as 24fits in the width

signed11 + 13 = 24, kept as -8V = 1: the signed answer is wrong

Warning:

C is carry-out (unsigned overflow); V is carry-into-MSB XOR carry-out-of-MSB (signed overflow). They are independent: either, both or neither can be set.

Compare with

Open the Binary arithmetic

This input is entered in the tool itself — it is too rich for a link to carry.

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)