C# Swapping Two Numbers Using Bitwise XOR Operator – Programming, Pseudocode Example, C# Programming Example
General

C# Swapping Two Numbers Using Bitwise XOR Operator

In this tutorial, we will swap two numbers using XOR( ^ ) operator.

Before solving the solution, let’s examine what is a bitwise XOR operator.   A bitwise XOR compares corresponding bits of two operands and returns 1 if they are equal and 0 if they are not equal.

 Here is Example:

 

Output:

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.