Open In App
Related Articles

Algorithms | Bit Algorithms | Question 2

Improve Article
Save Article
Like Article

What does the following C expression do? x = (x<<1) + x + (x>>1);


Multiplies an integer with 7


Multiplies an integer with 3.5


Multiplies an integer with 3


Multiplies an integer with 8

Answer: (B)


In the expression: x = (x<<1) + x + (x>>1);
(x<< 1) means left shift x by 1, by doing this we get, x*2.
(x>>1) means right shift x by 1, by doing this we get, x/2

After solving the above expression, we get
=x*2 + x + x/2 
= 3*x +x/2
=3.5*x,  Hence x is a multiple of 3.5
The expression multiplies an integer with 3.5.  See for more details:

Hence Option(B) is correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Last Updated : 01 Jun, 2021
Like Article
Save Article
Similar Reads