Efficient way to multiply with 7 - GeeksforGeeks
We can multiply a number by 7 using bitwise operator.
7n = 8n-n
unsigned Multiply9(unsigned N)
{
return ((N << 3) + N);
}
Read full article from Efficient way to multiply with 7 - GeeksforGeeks
We can multiply a number by 7 using bitwise operator.
7n = 8n-n
int
multiplyBySeven(unsigned
int
n)
{
/* Note the inner bracket here. This is needed
because precedence of '-' operator is higher
than '<<' */
return
((n<<3) - n);
}
return n + (n<<1) + (n<<2);
// will probably avoid overflow errors caused when doing
// return (n<<3) - n;
unsigned Multiply9(unsigned N)
{
return ((N << 3) + N);
}
Read full article from Efficient way to multiply with 7 - GeeksforGeeks