To get the 3rd bit:
n >> 2
shifts the 3rd bit all the way to the right.
(n >> 2) & 1
shifts the 3rd bit all the way to the right and then extracts the rightmost bit.
In general you want to shift by `i - 1` to get the i-th bit.
Do you index from zero or one?
For a binary number, which bit has the lowest index in your idea? is it the left most bit, or the right most one?
Is bit 1 (left most) or bit 0 (right most) having index 0?
Please specify a language in your question tags, you have taken multiple courses it is difficult to deduce a context in regards to which language 👍
Specified language added in tags.
Thank you for understanding 👍
I was going to propose this, but Schindlabua's method is way neater 😆
Just as an alternative though,
(n & (1 << index) ? 1 : 0)
* Where <n> is the number, and <index> is N - 1, so <index> would be 2 if you want to get the 3rd bit.