1011 0110 + 1001 0011 in 8 bits — binary arithmetic

exam standardthe result does not fit

Answer

01001001 with carry out 1

Why this example is worth doing

Two bytes whose sum exceeds 255, so the ninth bit is lost and the register holds a wrapped value. The page distinguishes carefully between what the hardware does — discard into the carry flag — and what it means, which depends entirely on whether the operands are signed. The same bits are an unsigned overflow here and, read as signed values, a signed overflow too, and the page shows both readings.

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

10110110 + 10010011 (8-bit, unsigned)

10110110 + 10010011 (8-bit, unsigned) — columns operand, bits, hex, unsigned, signed
operandbitshexunsignedsigned
A101101100xB6182-74
B100100110x93147-109
The digit above column i is the carry or borrow into column i. Bit 0 is the least significant column. — 10110110 + 10010011
row76543210
carry in01101100
A10110110
+ B10010011
result01001001

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

unsigned182 + 147 = 329, kept as 73carry out: the true sum needs one more bit

signed-74 + -109 = -183, kept as 73V = 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 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)