Lecture: 27
Objective: Understand how to use shift and add to multiply a variable by integer and fractional constants.

Multiplication by constants

When you add two numbers the result can have at most one more digit than the operands. For example, the 2-digit operands "50" when added to itself, 50 + 50 = 100 yields a 3-digit result. This result generalizes as follows. The sum of a pair of N-digit numbers generates a result with at most N+1 digits. Trying to "squeeze" a N+1 digit sum into a N-digit variable will generate an illegal result and a condition we call overflow. Multiplication is fundamentally different, the product of two numbers generates a result that can have up to two times the number of digits as the operands. For example, the 2-digit operands "50" when multiplied by itself, 50 * 50 = 2500 yields a 4-digit result. This result generalizes as follows. The product of a pair of N-digit numbers generates a result with at most 2*N digits. Trying to "squeeze" a 2*N digit product into a N-digit variable will generate an illegal result and a condition we call overflow.

You can multiply a binary number by a power-of-2 by shifting it left one bit. The mat
Given a 4-bit binary number B = b3 b2 b1 b0.  Using the definition of 
positional notation, these four bits are interpreted to have the value:
b3*2^3 + b2*2^2 + b1*2^1 + b0*2^0

Shifting B left one bit produces b3 b2 b1 b0 0.  Using the definition
of positional notation, these five bits are interpreted to have the value:
b3*2^4 + b2*2^3 + b1*2^2 + b0*2^1 + 0*2^0 = 2*(b3*2^3 + b2*2^2 + b1*2^1 + b0*2^0) = 2*B
A similar argument can be made that shifting a binary number to the right divides it by 2. The following table will come in handy during the next exercises.

i 2^i
3 8
2 4
1 2
0 1
-1 0.5
-2 0.25
-3 0.125
-4 0.0625
-5 0.03125
What follows is a sequence of problems that motivate our discussion. For each of the following problems, you are to multiply an 8-bit integer, called x8, or a 16-bit integer, denoted x16, by a constant and put the result into a variable y8, y16, y24, or y32 depending on the size of the result.