1. package main
    2. import "fmt"
    3. func main () {
    4. a := 1
    5. b := 2
    6. a = a + b
    7. b = a - b
    8. a = a - b
    9. fmt.Println(a,b)
    10. c := 1
    11. d := 2
    12. c = c^d
    13. d = c^d
    14. c = c^d
    15. fmt.Println(c,d)
    16. }
    1. 2 1
    2. 2 1

    异或:相同为0不相同为1

    Example:
    1:
    10101
    ^ 00000
    ——————-
    10101
    a^0=a

    2:

    swap of two variable - 图1
    10101
    ^ 11100
    ——————-
    01001

    swap of two variable - 图2
    01001
    ^ 11100
    ——————-
    10101