Learn Computer Science programming - C# and C++ Algorithms

 
Swaping

Swap the contents of m and n without using another variable. Use the triple XOR trick 
Code
 
Pseudocode



//Two numbers
    m = 0x2A;    //00101010  // 42
    n = 0xA5;    //10100101  // 165

//Swap them
    m = m ^ n;  //10001111  // 143
    n = m ^ n;   //00101010 = 0x2A = 42
    m = m ^ n;  //10100101 = 0xA5 = 165