Multiply a number by 5...

<p>Here’s a small brain teaser, assuming we’re using Java/C syntax at the moment (both are equivalent in this case), can you multiply a number by 5 without using the * and + operators?</p>

<p>Here we assume that a - -b === a+b so you cannot subtract by the negative of a number.</p>

<p>a = a / (1/5)</p>

<p>A * 5 = (a << 3) - a - a - a</p>

<p>@chendrix:</p>

<p>1/5 evaluates to an integer and ends up as 0, which will throw a division by zero error ;)</p>

<p>But you’re on the right track xD</p>

<p>@Kyt:</p>

<p>That was what I was looking for :D</p>

<p>a<<3 shifts 3 bits (1’s) into a which is equivalent to a<em>2</em>2*2</p>

<p>This however does not work for all n of real numbers as floating precision datatypes do not follow the above paradigm.</p>

<p>hate to do this, but this might work: -(-a - a - a - a - a) = 5*a</p>

<p>or 5.0/(1.0/a) following chendrix’s lead :D</p>