Dynamic inversion

for(i = 1; i <= n; i++) {
t = 0;
for(j = a[i]; j; j = j & (j - 1)) t += fwt[j];
for(j = a[i]; j <= n; j = (j | (j - 1)) + 1) ++fwt[j];
ret = (ret + i - t - 1) % 2; // All we need is just a parity of this number, so we take it modulo 2
}

can please anyone explain whats happenning in above code.what is the use of j& j-1 and j|j-1.thank you.The code is of dynamic inversion problem. DYNAINV.It Problem - CodeChef belongs to setter code