Given two 16–bit positive values stored in 32–bit integer variables, find the product using the 8–bit multiply operator that takes two 8–bit numbers and returns a 16–bit value.

The idea is to divide the given 16–bit numbers (say m and n) into 8–bit numbers first (say mLow, mHigh and nLow, nHigh). Now the problem is reduced to something similar to the multiplication of a 2–digit number with another 2–digit number. For example,

                                   [mHigh mLow]    ×
                                   [nHigh nLow]
                                   – – – – – – –
                    [mHigh * nLow] [mLow * nLow]
    [mHigh * nHigh] [mLow * nHigh]
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
[mHigh * nHigh] + [mLow * nHigh + mHigh * nLow] + [mLow * nLow]
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Following is the C++, Java, and Python implementation of the idea. We have used an unsigned char to represent an 8–bit number and unsigned short to represent a 16–bit number.

Download  Run Code

Output:

23472 in binary is 0101101110110000
2600 in binary is 0000101000101000
 
Normal multiplication m × n = 61027200
Using 8–bit multiplier m × n = 61027200

 
References: https://ccrma.stanford.edu/~hugo/cs/