1111 × 1111 — binary arithmetic

coren-bit × n-bit needs 2n bits

Answer

0000000011100001

Why this example is worth doing

The largest four-bit product, which needs eight bits to hold. That is the general rule — multiplying two n-bit values can need 2n bits — and it is why multiply instructions either produce a double-width result or expose the high half separately. The page makes the width point explicitly because truncating a product silently is a common and hard-to-find bug.

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

00001111 x 00001111 (8-bit unsigned)

00001111 x 00001111 (8-bit unsigned) — columns operand, bits, hex, unsigned, signed
operandbitshexunsignedsigned
A000011110x0F1515
B000011110x0F1515

Shift and add: one partial product per multiplier bit, each shifted left by its bit index. A 8 x 8 multiply needs 16 bits of product.

00001111 x 00001111 (8-bit unsigned) — columns bit index, multiplier bit, partial product, meaning
bit indexmultiplier bitpartial productmeaning
010000000000001111|A| << 0
110000000000011110|A| << 1
210000000000111100|A| << 2
310000000001111000|A| << 3
4000000000000000000 (multiplier bit is 0)
5000000000000000000 (multiplier bit is 0)
6000000000000000000 (multiplier bit is 0)
7000000000000000000 (multiplier bit is 0)

sum of partial products0000000011100001

product0000000011100001 = 225

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)