Author Topic: Swap two numbers using XOR  (Read 944 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Swap two numbers using XOR
« on: November 08, 2011, 11:58:41 am »
Here is the source code to swap two numbers using XOR operation:

Code:
//Source Code Listing

void main()
{
   int a = 25;
   int b = 50;

   a = a ^ b;
   b = a ^ b;
   a = a ^ b;
}


Here is the truth table for XOR operation:

A   B   A XOR B
0   0     0
0   1     1
1   0     1
1   1     0

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1