"mangesh" <ma************@walla.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I have following code .
unsigned int var1 = 5 ;
#define ISVAR (1 << 2)
Then what is output of
(ISVAR & var1) .
How to find it out on paper for various values of var1 says 4 , 1 , 2
ect .
Regards ,
Mangesh .
& is logical AND.
So, (ISVAR & var1) is (1 << 2) AND 5, while
(1 << 2 ) is 4 (1 left shifted 2 times).
So, we have the logical AND of 4 and 5.
In binary, 4 is 100 and 5 is 101. So, finally,
100 AND 101 = 100 = 4.
Serafeim