AmitDey wrote:
Now when we do x&(x-1)...ie. bitwise and we get 00001000... 00000111... ------------ 00001111...
:confused: This "&" is the bitwise operator for the logical function AND, so, with it you would get 00001000... 00000111... ----------- with operator & 00000000... What you need is the bitwise operator for the logical function OR. The operator is "|" so this operator would be the correct one, hence the expression is "x|(x-1)" 00001000... 00000111... ----------- with operator | 00001111...