Mid Coding

Check if two numbers have opposite signs?

public bool HaveOppositeSigns(int x, int y) {

return (x ^ y) < 0;

Explanation:

XOR of two numbers with opposite signs has the sign bit set (negative number).

More from C# Programming Tutorial

All questions for this course