using & operator

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
lcp
New poster
Posts: 2
Joined: Wed Apr 01, 2015 11:27 pm

using & operator

Post by lcp » Wed Apr 01, 2015 11:38 pm

Hi ,
x , y , m , n all lie in range [-10^4 , 10^4] .

so when i did
if ( (x & y) == 0) cout << "divisa ";

i got wrong answer.

But
if ( x== 0 || y== 0) gave okay .

what am i missing ??

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: using & operator

Post by sohel » Sat Apr 04, 2015 12:28 am

lcp wrote:Hi ,
x , y , m , n all lie in range [-10^4 , 10^4] .

so when i did
if ( (x & y) == 0) cout << "divisa ";

i got wrong answer.

But
if ( x== 0 || y== 0) gave okay .

what am i missing ??
They are not equivalent.
Suppose x = 8 and y = 1, then x&y is equal to 0.

lcp
New poster
Posts: 2
Joined: Wed Apr 01, 2015 11:27 pm

Re: using & operator

Post by lcp » Sat Apr 04, 2015 2:02 am

i should have used && . Thanks .

Post Reply

Return to “C++”