How to swap two numbers with the bitwise XOR operator in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main()
    {
        int x = 5;
        int y = 9;
    
        x ^= y; 
        y ^= x; 
        x ^= y;
    
        Console.Write(x + " " + y);
    }
}


/*
run:

9 5

*/

 



answered Mar 29, 2019 by avibootz

Related questions

1 answer 213 views
1 answer 254 views
1 answer 195 views
1 answer 208 views
1 answer 240 views
2 answers 260 views
...