reading off single bit value from int error

1. I was creating number that consists of these 2 bits (20th and 2nd)
2. I tryed to read exactly that 20th bit to see if its actually 1
Here is the code and the output i was getting.
Anyone knows why didnt i get my 1 or 0?

1
2
int x = 1048580;   //This is number 2^20 + 2^2 so  1000000000....0010
cout << (x & (1 << (20)));

1048576
When you do (x & (1 << 20)), you are ending up with either 0 or (1 << 20) because you are not shifting the result at all. Note that (1 << 20) equals 1048576.
so i have to shift it the opposite way and than mask with 1 right
Thank you very much man for got me thinking
(( x >> 20) & 1) works :)
Topic archived. No new replies allowed.