0
What does j-=j & (-j) mean
4 Answers
+ 7
You have 2 parts to this expression
1) a-=b is same as ( a = a - b )
2) ( a & b ) gives bitwise AND of the *a* and *b* ( logical AND of each bit in the binary representation of the numbers )
Now in case of j-=j&(-j)
It becomes
j = j - (j&(-j))
And now as both * j * and * - j * will only differ at sign bit so the bitwise AND of both would simply be absolute value of *j*
So for positive value of * j * the result will always be zero and for negative values of * j * it will be double the value in * j *
+ 2
Coder you got that right.
+ 1
Thanks for explaining dude
0
So if j=1
Then
In binary.
sign
bit
+j. = (0) 1
-j = (1) 1
-------------
j&(-j) = (0) 1
and
j-=1
so
j=1-1=0
???????