Multiplication. Wikipedia topic "binary multiplier" 23 * 14 = 00010111 * 00001110 By loop Add 23 to a sum 14 times. Very inefficient. Looping add requires 14 adds and 14 loop tests Various types of Binary multiplication. Shift and add - basic technique learned in school applied to binary. While any of the bits of 2nd number(multiplier) not zero. If the least significant bit of 2nd number is 1, Add 1st number(multiplicand) to sum. EndIf Shift 1st number left (*2) Shift 2nd number right (/2) ( logical shifts shift least/most significant bit and pad most/least significant bit with zero ) EndWhile 23 * 14 = 00010111 * 00001110
Multiplicand Multiplier Masked Sum LSB (mask) value 10111 * 0 0 0 101110 * 1 101110 101110 1011100 * 1 1011100 10001010 10111000 * 1 10111000 101000010 --------------------------------------------- Most CPUs would stop here. 101110000 * 0 0 101000010 1011100000 * 0 0 101000010 10111000000 * 0 0 101000010 101110000000 * 0 0 101000010 |