I'm getting quite confused here.
If I have a number, let's call it 16 here, and I want to check if a particular bit is set. I would do the following:
if (16 & (2 ^ bitPosition) == (2 ^ bitPosition))
Right?
Why then, for bitPosition = 2, is that statement returning true? Shouldn't it be false, as only bitPosition = 4 is true in that case?
My understanding was:
Bit|Val
0 |1
1 |2
2 |4
3 |8
4 |16
5 |32
6 |64
7 |128
I've never worked with this kind of thing before and it's baffling me.