explain this

if (counter & (1<<j))
checks if the j-th bit of counter is set.
what means set ?How can a bit of any number be set ?

set means that bit is 1.

when we talk about a bit being set we mean that in the binary representation of the number the j’th bit is 1.
Like binary representation of 4 is 100 here 3rd bit is set .
To set the 2nd bit we can do num=num|2 where num is 4 here.