英文:
Go "&^" operator, what does it mean?
问题
我正在努力理解Go语言中的&^
和&^=
运算符的含义。我在文档中找不到答案(文档中说明它是一个位清除运算符,但对我来说并没有太大帮助),也没有通过尝试找到答案。
特别是,我想知道Python中是否有相应的等价运算符。
英文:
I am struggling to understand what the &^
and &^=
operators mean in Go. I cannot find an answer either in the documentation (which states it's a bit clear operator, but it does not help me much) or by trials.
In particular, I want to know if there is an equivalent in Python.
答案1
得分: 8
这些是“AND NOT”或“位清除”运算符,对于清除左操作数中在右操作数中设置的位非常有用。
我将“有用”用引号括起来,因为所有从C语言派生位运算的其他语言都是使用位与&
和位非~
来实现这一点;因此,在Python中,5 &^ 2
就等同于5 & ~2
;而在Python中,Go语言中的a &^= 3
就等同于a &= ~3
。
英文:
These are the "AND NOT" or "bit clear" operators, "useful" for clearing those bits of the left-hand side operand that are set in right-side operand.
I put the "useful" in quotes since all other languages that derive the bitwise operations from C one does this with bitwise AND &
and bitwise NOT ~
; thus 5 &^ 2
would be just 5 & ~2
in Python; and a &^= 3
of Go would be a &= ~3
in Python.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论