SHARE
TWEET

Untitled

a guest Dec 14th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int myXOR(int x, int y)
  2. {
  3.     int res = 0; // Initialize result
  4.      
  5.     // Assuming 32-bit Integer  
  6.     for (int i = 31; i >= 0; i--)                      
  7.     {
  8.        // Find current bits in x and y
  9.        bool b1 = x & (1 << i);
  10.        bool b2 = y & (1 << i);
  11.          
  12.         // If both are 1 then 0 else xor is same as OR
  13.         bool xoredBit = (b1 & b2) ? 0 : (b1 | b2);          
  14.  
  15.         // Update result
  16.         res <<= 1;
  17.         res |= xoredBit;
  18.     }
  19.     return res;
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top