Given two signed integers, write a function that returns true if the signs of given integers are different, otherwise false.
Read full article from Detect if two integers have opposite signs | GeeksforGeeks
bool
oppositeSigns(
int
x,
int
y)
{
return
((x ^ y) < 0);
}
bool
oppositeSigns(
int
x,
int
y)
{
return
((x ^ y) >> 31);
}
We can also solve this by using two comparison operators.
bool
oppositeSigns(
int
x,
int
y)
{
return
(x < 0)? (y >= 0): (y < 0);
}