I read a wiki that says for multiplication the CPU adds!
From wiki:
Pass the only weight-1 wire through, output: 1 weight-1 wire
Pass the two weight-2 wires through, outputs: 2 weight-2 wires
Add a full adder for weight 4, outputs: 1 weight-4 wire, 1 weight-8 wire
Add a full adder for weight 8, and pass the remaining wire through, outputs: 2 weight-8 wires, 1 weight-16 wire
Add a full adder for weight 16, outputs: 1 weight-16 wire, 1 weight-32 wire
Pass the two weight-32 wires through, outputs: 2 weight-32 wires
Pass the only weight-64 wire through, output: 1 weight-64 wire
I not understand whole, but I think it keeps adding then if it not know how to add it pass and goes next addition. here full article: http://en.wikipedia.org/wiki/Dadda_tree
I do lot research and I think it is slow. So instead of the CPU doing multiplication I want to do it myself.
I wrote this function:
function do_multiply($a, $b)
{
while($b > 0) {
$a = $a + $a;
$b = $b-1;
}
All I want to do is if I asked function to multiply 2 and 3, I want to add 2 to 2, three times, correct?
So I want to do this:
2+2+2
This is same as 2*3, correct?
When I run this it gives me 16. Why do I get the wrong answer?
{
}