按位异或
按位异或 | |
---|---|
术语名称 | 按位异或 |
英语名称 | bitwise XOR |
别名 | 位异或 |
按位异或是位运算的一种,在二进制串中每个对应的二进制位上执行逻辑异或。
定义
按位异或 | |
---|---|
运算名称 | 按位异或 |
运算符号 | |
Latex | |
运算对象 | 二进制串 |
运算元数 | 2 |
运算结果 | 二进制串 |
定义域 | [math]\displaystyle{ \mathbb{B}^n \times \mathbb{B}^n }[/math] |
陪域 | [math]\displaystyle{ \mathbb{B}^n }[/math] |
对两个长度相同的二进制串 [math]\displaystyle{ x_1 x_2 \cdots x_n }[/math] 和 [math]\displaystyle{ y_1 y_2 \cdots y_n }[/math] ,对每位进行逻辑与得到二进制串 [math]\displaystyle{ a_1 a_2 \cdots a_n }[/math] ,其中 [math]\displaystyle{ a_i = x_i \oplus y_i = x_i \bar{y_i} + \bar{x_i} y_i = (x_i + y_i)(\bar{x_i} + \bar{y_i}) }[/math] ,称这种运算为按位异或(bitwise XOR)。
性质
运算性质:
多元按位异或
由于是一种满足结合律的运算,可以定义多元按位异或运算。
位运算 | ||
---|---|---|
按位运算 | 按位运算 | 按位取反、按位与、按位或、按位异或 |
特殊情况 | 掩码、位设置、位清除、位反转 | |
移位运算 | 算术移位 | 算术左移、算术右移 |
逻辑移位 | 逻辑左移、逻辑右移 | |
循环移位 | 循环左移、循环右移 |