EXTRACT_BIT

Hello everybody,

could anyone kindly explain to me how does this line of code work step by step?

# define EXTRACT_BIT(n, i) ((n&(1<<i))?1:0)

Sincerely

(1<<i) left shifts one by i places.
(n&(1<<i)) performs a logical AND on n and the result of the above. That is, it pics out the (i+1)th bit.
?1:0 return one (true) if the (i+1)th bit is set or zero (false) if it isn't.
Topic archived. No new replies allowed.