Skip to content
Related Articles

Related Articles

Improve Article

Algorithms | Bit Algorithms | Question 3

  • Last Updated : 17 May, 2019

What does the following C expression do?

 x = x & (x-1) 

(A) Sets all bits as 1
(B) Makes x equals to 0
(C) Turns of the rightmost set bit
(D) Turns of the leftmost set bit


Answer: (C)

Explanation: The expression simply turns off the rightmost set bit. For example, if x = 14 (1110), x – 1 = 13 (1101) it returns resultant as (1100) i.e, 12 .

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :