Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
anematode
4 months ago
|
parent
|
context
|
favorite
| on:
Too much discussion of the XOR swap trick
It's not quite the same as XOR swap, but a trick I've found handy is conditionally swapping values using XOR:
int a, b; bool cond; int swap = cond ? a ^ b : 0; a ^= swap; b ^= swap;
If
cond
is highly unpredictable this can work rather nicely.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: