Skip to content

Instantly share code, notes, and snippets.

@phedoreanu
Created May 2, 2016 16:56
Show Gist options
  • Select an option

  • Save phedoreanu/3bf8e105b4746f932be123db45ae8567 to your computer and use it in GitHub Desktop.

Select an option

Save phedoreanu/3bf8e105b4746f932be123db45ae8567 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func xorSwap(x, y *int) {
if x != y {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}
func main() {
x, y := 1, 0
fmt.Println(x, y)
xorSwap(&x, &y)
fmt.Println(x, y)
}
@phedoreanu
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment