什么是golang中的^ 0?

我在代码库中看到^ 0.

例:

type stat struct {
  ...
  min int64
  ...
}

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(在有符号数据类型上).所以这是一种写作方式:

newStat := stat{min: -1}

相关文章

什么是Go的接口? 接口可以说是一种类型,可以粗略的理解为他...
1、Golang指针 在介绍Golang指针隐式间接引用前,先简单说下...
1、概述 1.1 Protocol buffers定义 Protocol buffe...
判断文件是否存在,需要用到"os"包中的两个函数: os.Stat(...
1、编译环境 OS :Loongnix-Server Linux release 8.3 CPU指...
1、概述 Golang是一种强类型语言,虽然在代码中经常看到i:=1...