
上QQ阅读APP看书,第一时间看更新
xor
The xor function compares the corresponding bits of two values. If the corresponding bits are the same, it gives 0, and if they are different, it gives 1.
Look at this example:
fun main(args: Array<String>) {
val a=2
val b=3
print(a xor b)
}
Given is the output:
1
Here's the explanation:
2 = 10 (Binary format)
3 = 11 (Binary format)
Bitwise XOR of 2 and 3
in binary
10 XOR 11
01 = 1 (Decimal format)