Beetwise

Binary multiplication

Binary multiplication adds a shifted copy of the first value for each bit of the second.

A bit with the value 1 contributes a copy. A bit with the value 0 contributes nothing.

The value 1010 times 0011 gives 11110, which is 30.

Try binary multiplication in the bit editor

The product of 1010 and 0011. Edit the expression or select a bit to flip it.

7
6
5
4
3
2
1
0
30
value · 8 bits · unsigned
binary
0b00011110

Binary multiplication step by step

Calculate 1010 times 0011:

  1. Bit 0 of 0011 has the value 1. Add 1010, with no shift.
  2. Bit 1 of 0011 has the value 1. Add 1010 shifted left by 1, which is 10100.
  3. Bit 2 and bit 3 of 0011 have the value 0. Add nothing.
  4. Add the parts: 1010 plus 10100 gives 11110.
  5. The result is 11110, which is 30.

A multiplication by a power of two is a shift

A multiplication by a power of two is a shift
ExpressionShiftResult
x * 2x << 1Double
x * 4x << 2Four times
x * 8x << 3Eight times
x * 10(x << 3) + (x << 1)Eight times plus two times
x / 2x >> 1Half, with the remainder dropped

Where binary multiplication is used

A processor without a multiplier builds one from shifts and additions.

A fixed point calculation multiplies, then shifts the result back down.

A compiler turns a multiplication by a constant into shifts and additions.

Binary multiplication: points to note

  • A product needs as many bits as both inputs together. Two 8-bit values need 16 bits.
  • A product that does not fit wraps. At a bit width of 8, 20 times 20 gives 144 rather than 400.
  • A shift multiplies by a power of two only. Other factors need an addition as well.
  • A signed multiplication needs the sign handled, because the top bit is not part of the magnitude.

The full bit editor

The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.

Open this value in the full editor

Questions about binary multiplication

What is 1010 times 0011 in binary?
The result is 11110, which is 30 in decimal.
Why does a left shift double a value?
Every bit moves to the next higher position, and each position holds twice the one below it.
How many bits does a product need?
As many as both inputs together. Two 8-bit values give a result of up to 16 bits.