1.

Which of these expressions will isolate the rightmost set bit?(a) x = x & (~x)(b) x = x ^ (~x)(c) x = x & (-x)(d) x = x ^ (-x)The question was posed to me in examination.My doubt is from Integer Types topic in division Types, Pointers, Arrays & Structures in C++ of C++

Answer»

Correct option is (C) x = x & (-x)

The best explanation: NEGATIVE of a NUMBER is stores as 2;s complement in C++, so when you will take AND of x and (-x) the rightmost digit will be preserved.



Discussion

No Comment Found

Related InterviewSolutions