I am trying to understand one C++ program, which has a loop written as follows:

for(int i = 0; i < (1<<m); ++i) {
    for(int k = 0; k < m; ++k) {
        if(i&(1<<k)) {
            //in subset
        }
    }
}

I do not understand how the loop control condition

i < (1<<m);

works?

Besides, I do not understand how the if condition

if(i&(1<<k))

works?

I would guess your problem is with the << and & operators.

<< is the bit shift operator
& is the AND operator

With that you should be able to look them up and figure the statements out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.