How to access the bit at a particular index?
This can be done by running an AND between n and a number with it's ith bit set to 1, which can be obtained by 1 &lt;&lt; i. The result of this operation will be zero if the ith bit in n is zero, or 1 &lt;&lt; i otherwise.

Case of zero:

n     = 10111
m     = 01000 (1 &lt;&lt; 3)
n &amp; m = 00000


Case of one:

n     = 10111
m     = 00100 (1 &lt;&lt; 2)
n &amp; m = 00100 (1 &lt;&lt; 2)


So:

$m = 1 &lt;&lt; i$

$\text{if}\; (n \;\&amp;\; m == 0)$

$\;\;\;\;\text{return} \;0$

$\text{else}$

$\;\;\;\;\text{return} \;1$