what is a &^= b means?

131 views
Skip to first unread message

xie cui

unread,
Apr 24, 2021, 8:42:01 AM4/24/21
to golang-nuts
func f(a, b int) int {
    a &^= b
    return a
}
what is this op (&^=) means?

xie cui

unread,
Apr 24, 2021, 8:46:22 AM4/24/21
to golang-nuts
 it means OANDNOT!!!

Jan Mercl

unread,
Apr 24, 2021, 8:55:36 AM4/24/21
to xie cui, golang-nuts
There is a wonderful source of answers to such questions here:
https://golang.org/ref/spec

Brian Candler

unread,
Apr 24, 2021, 11:17:12 AM4/24/21
to golang-nuts
More or less equivalent to:

a = a & (^b)

where & is bitwise AND operator, and ^ is bitwise NOT operator.  Upshot: any bit which is 1 in 'b' causes the corresponding bit in 'a' to be set to 0.

Wojciech S. Czarnecki

unread,
Apr 24, 2021, 11:17:28 AM4/24/21
to golan...@googlegroups.com
Dnia 2021-04-24, o godz. 05:42:01
xie cui <cuiw...@gmail.com> napisał(a):

> what is this op (&^=) means?

This is common idiom for "bit clear" in Go

Chinese: https://gfw.go101.org/article/operators.html

English:
https://go101.org/article/operators.html
https://golang.org/ref/spec#assign_op
https://yourbasic.org/golang/bitwise-operator-cheat-sheet/

Hope this helps,


--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE
Reply all
Reply to author
Forward
0 new messages