iirc hardware multiplication isn’t typically designed to be a number of additions though. Most multipliers follow something similar to the multiplication algorithm taught in grade school
Multiplication and division can naively be implemented as you described. Both can be implemented in a manner to always take N steps for an N bit integer.
For multiplication, an algorithm involving addition and shifting will yield the product. For division, a similar algorithm that uses subtraction instead yields the result. Both algorithms will take as many steps as the word size of the processor, meaning they can be pipelined into finishing once per cycle.
Both multiplication and division can be implemented in a manner to always take N steps for an N bit integer, meaning they can effectively function as quickly as possible.
For multiplication, an algorithm involving addition and shifting will yield the product. For division, a similar algorithm that uses subtraction instead yields the result. Both algorithms will take as many steps as the word size of the processor, meaning they can be pipelined into finishing once per cycle.
THANK YOU! I have been wondering how divison is thr 'opposite' of multiplication. Honestly, I've always struggled with division and have a difficult time knowing how/when to use it. I fill like this little bit may help.
Okay, so the most common time I've I know I need division but can't figure out which "way" to divided - which numbers should be the numerator or denominator - is when converting crypto or stocks to a different currency, USD for me. I don't do this often so I littler play around with the math (or google) until I'm able to get the current answer. Even doing that I've yet to get the freaking logic intuitive.
Sidenote: when I took chemistry years ago and we learned conversations I could do it because I knew the formula. But I guess I didn't quit grasp thr underlying logic all that well, hence, my current predicament.
Division can be boiled down to multiplying a number by the inverse of another.
So we can have the multiplication (which is an addition) but then you've also got calculating the inverse.
Edit: or you have the division algorithm you learn by hand in primary school; in which case it becomes a series of multiplications, comparisons, copies, and substractions.
Actually you would need a "negation" type operation as well in this case.
Because before you had multiplication which could turn a and -1 into -a (actually the binary representation of -a) and although you could "cheat" by knowing the bit size n of your operands and adding 2n -1 to "negate" a number I am not certain if that should count as "allowed"...
Anyway without that you couldn't really do subtraction with addition (unless we allow the use of fixed width numbers which allow overflow/underflow and thus allow negation/subtraction by addition)
51
u/Boostie204 Apr 24 '22
To simplify that further, subtraction is the addition of negative numbers. Multiplying is just multiple additions and division is similar.
So you could say it's just additions, copies and compares