Is there Kotlin analogue to Java ^=
(xor and assign) operator?
For instance, in Java we can simply write
a ^= b
// a = a ^ b
It looks like in Kotlin we need to assign value explicitly
a = a xor b
Is it possible to avoid duplication of variable a
in Kotlin code?
Unlike C, C++ and Java, Kotlin doesn’t have bitwise operators like |(bitwise-or), &(bitwise-and), ^(bitwise-xor), << (signed left shift), >>(signed right shift) etc.
For performing bitwise operations, Kotlin provides following methods that work for Int and Long types -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With