Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmAlgorithms | Bit Algorithms | Question 2

Algorithms | Bit Algorithms | Question 2

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

(A)

Multiplies an integer with 7

(B)

Multiplies an integer with 3.5

(C)

Multiplies an integer with 3

(D)

Multiplies an integer with 8

Answer: (B)
Explanation:

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
=7x/2
=3.5*x,  Hence x is a multiple of 3.5
The expression multiplies an integer with 3.5.  See for more details: https://www.neveropen.co.za/multiply-an-integer-with-3-5/

Hence Option(B) is correct.

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments