Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Binary multiplication (http://www.go4expert.com/forums/binary-multiplication-t23871/)

 Croatoan 15Nov2010 02:03

Binary multiplication

Can sb give me a tip for recursive multiplication of two binary numbers (their lenght is 2^n)! I need only recursive to implement it in c++ code,

 xpi0t0s 15Nov2010 14:56

Re: Binary multiplication

What's recursive multiplication? Could you outline the algorithm, i.e. how would you do it on paper?

 Croatoan 15Nov2010 19:49

Re: Binary multiplication

x=xl * 2^(n/2)+xr (n=2^k, k e 1,2,3)
y=yl * 2^(n/2)+yr

x*y=xl * 2^(n/2) * yl * 2^(n/2) + xl * 2^(n/2) * yr +
xr*yl * 2^(n/2) + xr*yr

how to implement that in c++

 xpi0t0s 16Nov2010 04:14

Re: Binary multiplication

Where are you stuck?
2^(n/2) appears to be a constant (let's say you put that in c), so the first equation
x=xl*c+xr
translates into C++ as
x=xl*c+xr;

You should be able to take it from there.

 All times are GMT +5.5. The time now is 15:02.