Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Yes, it results from bit property of number
- a = 0
- b = 1
- a ^= b // a = 0 ^ 1 = 1
- b ^= a; // b = 1 ^ 1 = 0
- a ^= b; // a = 1 ^ 0 = 1
- result:
- a = 1
- b = 0
- What really happens?
- Variable A
- a = a ^ b
- a = a ^ b ^ ( b ^ a ^ b )
- Usage count of a = 2. XOR value is 0, it disappears.
- Usage count of b is 3, this value will be a result.
- Variable B
- b = b ^ a
- b = b ^ (a ^ b)
- Usage count of a = 1. this value will be a result
- Usage count of b is 2, XOR value is 0, it disappears.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement