Go "&^" operator, what does it mean?

huangapple go评论75阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2016年4月3日 12:53:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/36381749.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定