I am operating on individual bits of two integers, (i am using g++ for compilation on Ubuntu machine).
In some intermediate step, I have the bit representations as
q = 11000000000000000000000000000000
q_1 = 00000000000000000000000000000001
Now I want to check whether unit's places of q and q_1 are both same or not. so, I am checking (*q)&1==q_1
in the if condition, and its working fine.
But whenever I want to check that unit's place of q is 0 and that of q_1 is 1, I thought I should do ((*q)&1==0) && (q_1==1)
, but it is not working out as expected. For debugging, I cout
ed the values of ((*q)&1==0)
and (q_1==1)
individually and they got printed as 1
. However, the value of ((*q)&1==0) && (q_1==1)
got printed as 0. Why?
*EDIT : * In the function, q was passed by reference, so I am using *q to get the value..
*
. – hyde Feb 1 '13 at 11:47(*q)
because of not knowing the precedence, got confused because both the operands of&
were1
and still I was getting0
as output... – Shaarad Dalvi Feb 1 '13 at 11:51func(int *q,int*m)
– Shaarad Dalvi Feb 1 '13 at 11:52&
,^
,|
are on the wrong side of comparison operators, probably because they were confounded with logical operators), or unclear (<<
,>>
). – starblue Feb 2 '13 at 9:02