The caret sits under the first bit of the number in memory as it's shifted by a decreasing number of bits, and the & isolates the current bit by clearing the remaining bits.
You should do like >>4 is doing and work through the code by hand, since you presumably understand at least how each bitwise operator works. Over time understanding what's going on becomes quite a bit more natural. You're spraypainting, man.
Now let's say you want to access(find out if it's set or not(0 or 1)) the least significant bit of a number:
A == 10101
all you have to do is perform an AND 1 operation on A
A == 00..0010101
1 == 00...000001
A & 1 == 00.......01
So, how do you find out the value of an arbitrary bit k?
You shift the value k bits to the right, thus getting the k-th bit as the least significant bit then do an AND 1 test. like in your code int bit = ((n >> k) & 1);
Another way would be bit = (n&(1<<k))?1:0, this just creates a number with the k-th bit set (000..01 => 000..100..k-1 times..00) and then and tests the original number. The returned value would either be 0 if it's not set or a positive value (equal to 1<<k), which you could use in an if test. Another way to do your task would be: