drjun1994 2017-05-04 11:53
浏览 105
已采纳

Go为什么有一个“位清除(与非)”运算符?

Why does Go have &^, the "bit clear (AND NOT)" operator?

Is there ever any difference between a &^ b and a & ^b?

  • 写回答

1条回答 默认 最新

  • douwu8524 2017-05-04 12:41
    关注

    There's a subtle difference that makes dealing with literals and untyped constants easier with the explicit bit clear operator.

    Untyped integers have their default type as int so something like a := uint32(1) & ^1 is illegal as ^1 is evaluated first and it's evaluated as ^int(1), which equals -2. a := uint32(1) &^ 1 is legal however as here 1 is evaluated as uint32, based on the context.

    There could also be some performance gains in having an explicit bit clear, but I'm not too sure about that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做数电题要具体的步骤
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真
  • ¥15 关于#c语言#的问题,请各位专家解答!
  • ¥15 这个如何解决详细步骤