[Solved] cant understand usage of bitwise operations [closed]


for(int i=0; i<(1<<N); i++) is used to do the combination:
it loops from 0b00000 to 0b11111

The following code:

long long sum=0;
for(int j=0; j<N; j++)
    if(i & (1<<j))
        sum+=a[j];
}

does the sum according to the previous ‘mask’:
so with i == 0b1010, sum will be a[1] + a[3] (mask index starts from right).

solved cant understand usage of bitwise operations [closed]