【发布时间】:2013-10-10 18:58:09
【问题描述】:
我在代码库中看到了 ^0。
例子:
type stat struct {
...
min int64
...
}
newStat := stat{min: ^0}
^0 是什么意思?
【问题讨论】:
标签: go bitwise-operators twos-complement
我在代码库中看到了 ^0。
例子:
type stat struct {
...
min int64
...
}
newStat := stat{min: ^0}
^0 是什么意思?
【问题讨论】:
标签: go bitwise-operators twos-complement
根据the docs:
^x 按位补码是 m ^ x,其中 m = "all bits set to 1" for
无符号 x 和 m = -1 用于有符号 x
表示^0与其他主流语言中的~0相同。
在two's complement(大多数编程语言采用)上,零补码的值为 -1(在有符号数据类型上)。所以这是一种写法:
newStat := stat{min: -1}
【讨论】: