【golang 学习】知识点——位操作运算符&^

来源:互联网 发布:天猫超市和淘宝的区别 编辑:程序博客网 时间:2024/05/30 05:25

位操作运算符&^用于按位置零(AND NOT)(按y置零x):

表达式z = x &^ y结果z

如果对应y中bit位为1的话,z的bit位为0,否则对应的bit位等于x相应的bit位的值。

var x uint8 = 1<<1 | 1<<5var y uint8 = 1<<1 | 1<<2fmt.Printf("%08b\n", x) // "00100010", the set {1, 5}fmt.Printf("%08b\n", y) // "00000110", the set {1, 2}fmt.Printf("%08b\n", x&^y) // "00100000", the difference {5}