Multiplication of binary numbers is much simpler than multiplication of decimal numbers. The multiplication table for binary numbers can be expressed as follows with * representing multiplikation:
- 0 * 0 = 0, 0 * 1 = 0, 1 * 0 = 0, 1 * 1 = 1.
Multiplication of a binary number n by the binary number 10 (=2) is done by adding the bit 0 to the right of the binary representation of n.
Multiplication of a binary number n by the binary number 100 (=4) is done by adding two bits 0 to the right of the binary representation of n.
Multiplication of a binary number n by the binary number 1000 (=8) is done by adding three bits 0 to the right of the binary representation of n.
And so on. Watch this illustration and play with the code.
Multiplication of a binary number n with a binary number m is done by multiplying n by each bit of m and then adding up.
Watch this multiplication machine and play with the code.
To do:
- Motivate why a*b = b*a for natural numbers a and b. (commutative law for multiplication)
- Motivate why a*(b + c) = a * b + a * c for natural numbers a, b and c. (distributive law)