Use of (1<<len)

void filter(int n, char a[])
{
int j = 0;

while (n > 0)
{
	int last_bit = (n & 1);
	if (last_bit)
	{
		cout << a[j];
	}
	j++;
	n = n >> 1;
}
cout << endl;

}

void print_subsets(char a[])
{
int len = strlen(a);
for (int i = 0; i < (1 << len); i++)
{
filter(i, a);
}
}

Can you explain to me why are we writing (1<<len) as the condition in the for loop in print_subsets() function.

Hello @Rohit39 this is shifting in bit manipulation.
to check about the bits.
this means that there i hight bit i.e 1 at this length number rest all 31 bits will be zero.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.