'What does the statement if (counter & (1<<j)) mean and how does it work?
I was working on an algorithm of sub sequences.
What is the meaning of the statement:
if (counter & (1<<j))
within the context of the program below:
void printSubsequences(int arr[], int n)
{
unsigned int opsize = pow(2, n);
for (int counter = 1; counter < opsize; counter++)
{
for (int j = 0; j < n; j++)
{
if (counter & (1<<j))
cout << arr[j] << " ";
}
cout << endl;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
