Google News
logo
CPP - Quiz(MCQ)
Which of these expressions will make the rightmost set bit zero in an input integer x?
A)
x = x | (x-1)
B)
x = x & (x-1)
C)
x = x | (x+1)
D)
x = x & (x+2)

Correct Answer :   x = x & (x-1)


Explanation : If x is odd the last bit will be 1 and last bit of x-1 will become 0. If x is even then last bit of x will be 0 and last bit of x-1 will become 1. In both case AND operation of 1 and 0 will be 0. Hence last bit of final x will be 0.

Advertisement