When you don't understand a bit of code, look at it and dissect it into it's component parts.
if(c&(1<<j))
Breaks down into
if (...)
and
c&(1<<j)
The first part I know you understand - it's a normal
if
, and the second part is the condition which evaluates to true or false.
c & (1 << j)
;Is also in two parts:
c & ...
And
1 << j
The first part is a binary AND of the two values: c and the second part, and a binary AND is simple: for each bit in the inputs, the resulting bit is 1 if and only if both the input bits are 1. Otherwise it's a 0. (
Interesting Facts about Bitwise Operators in C - GeeksforGeeks[<a href="https://www.geeksforgeeks.org/interesting-facts-bitwise-operators-c/" target="_blank" title="New Window>^] should help)
The second part is also simple: it's a 1 shifted j places to the right (the link above also explains this). So if j is 0 then it results in 1, for j == 1 it results in 2, for j = 2 it gives 4, and so on.
So the whole if is checking for a 1 bit in a specific position in
c
This is all in the documentation:
Operators in C / C++ - GeeksforGeeks[
^]