What does (number & -number) mean in bit programming? [duplicate]
This question already has an answer here: meaning of (number) & (-number) 3 answers For example: int get(int i) { int res = 0; while (i) { res = (res + tree[i]) % MOD; i -= ( (i) & (-i) ); } return res; } A tree update function: void update(int i, int val) { while (i <= m) { tree[i] = (tree[i] + val) % MOD; i += ( (i) & (-i) ); } } Can you please explain what they do in the code by using ( (i) & (-i) ) ? This two functions are a modified implementation of a Binary index tree (Fenwick tree) data structure. Here is two pictures to supplement MikeCAT's answer showing how i variable updates for