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 146 views
1 answer 176 views
1 answer 139 views
1 answer 138 views
1 answer 159 views
2 answers 149 views
...