Check if two integers have different signs

boolean diffSigns(int x, int y) {
  return (x ^ y < 0);
}

boolean diffSigns2(int x, int y) {
  return (x < 0) ? (y > 0) : (y < 0);
}

// C++ version
bool diffSigns3(int x, int y) {
  return (x ^ y >> 31);
}


你可能感兴趣的:(Check if two integers have different signs)