# Thread: Multiplying without the astrerisk

1. ## Multiplying without the astrerisk

Rewrite the following function so that the following conditions are
satisfied:
A) the multiplication operator ('*') is not used.
B) the division operator ('/') is not used.
C) the function does not make use of loops.
D) And no sneaky using assembly either!

int MultiplyBy321(int value)
{
int rslt;

rslt = value * 321;

return rslt;
}

how would something like that be done?

2. The first thing would be to pay attention to your teacher in the future so you don't have to ask other people to do your homework. The second would be to look up bit shifting and break 321 down into bitshiftable bites.

3. Well how abt using goto statements.. It is some what a loop.. can GOTO be used..

4. this isnt for school or anything like that this is for my own use, it is on that gearbox test that i requested and i have no idea how to do it....and i think using the goto statement would be considered a loop

5. The only way a goto would work in this situation would be ugly as sin (same as using a for loop to "fake" it). Look up bitshifting. Salem's example is right on for what I'm talking about. Bitshifting gives the same outcome as multiplying but is faster and only works when one of the numbers is a power of 2 (2,4,8,16,etc).

For numbers that aren't (like 321), you have to break it down into ones that are and add them up.

6. does anyone know of an online tutorial for that?

7. Originally posted by grmoo
does anyone know of an online tutorial for that?

8. 321 =>
256 + 64 + 1 =>
2^8 + 2^6 + 2^0 =>

9. Or "cheat"
result = pow(10, log10(val)+log10(321) );
I think it is the best idea I've ever seen.

10. Code:
```int MultiplyBy321(int Number)
{
return (Number + Number + Number + ... + Number); //321 times
}```