什么是golang中的^ 0?

前端之家收集整理的这篇文章主要介绍了什么是golang中的^ 0?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在代码库中看到^ 0.

例:

  1. type stat struct {
  2. ...
  3. min int64
  4. ...
  5. }
  6.  
  7. newStat := stat{min: ^0}

^ 0是什么意思?

根据 the docs

^x bitwise complement is m ^ x with m = “all bits set to 1” for

unsigned x and m = -1 for signed x

这意味着^ 0与其他主流语言中的〜0相同.

two’s complement(大多数编程语言采用)上,零补码的值为-1(在有符号数据类型上).所以这是一种写作方式:

  1. newStat := stat{min: -1}

猜你在找的Go相关文章