07丨运算符
07丨运算符
算术运算符

比较运算符

用==比较数组
- 相同维数且含有相同个数元素的数组才可以比较
- 每个元素都相同的才相等
逻辑运算符

位运算符

与其他主要编程语言的差异
&^按位置零
1 &^ 0 -- 1 1 &^ 1 -- 0 0 &^ 1 -- 0 0 &^ 0 -- 0
位运算符
右边是1, 结果是0
右边是0,左边的什么就是什么
package ch4 import "testing" const ( Readable = 1 << iota Writable // 2 Executable //4 ) func TestCompareArray(t *testing.T) { a := [...]int{1, 2, 3, 4} b := [...]int{1, 3, 2, 5} //c := [...]int{1, 2, 3, 4, 5} d := [...]int{1, 2, 3, 4} t.Log(a == b) //false 元素相同,顺序不同 //t.Log(a == c) // 长度不一样不能进行对比 t.Log(a == d) //true t.Log(Readable, Writable, Executable) // operator_test.go:20: 1 2 4 } func TestBitClear(t *testing.T) { a := 7 //0111 // operator_test.go:27: true true true a = a &^ Readable // operator_test.go:27: false true true a = a &^ Executable // operator_test.go:27: true true false t.Log(a&Readable == Readable, a&Writable == Writable, a&Executable == Executable) // false true false }
本文来自博客园,作者:元贞,转载请注明原文链接:https://www.cnblogs.com/yuleicoder/articles/14305459.html
浙公网安备 33010602011771号