Kotlin has bitwise operations available for Int and Long only, which are very different from those in Java. The following table shows these operations:
Bitwise operation | Purpose | Example |
shl(bits) | Signed shift left (Java's <<) | 123 shl 1 |
shr(bits) | Signed shift right (Java's >>) | 123 shr 1 |
ushr(bits) | Unsigned shift right (Java's >>>) | 123 ushr 1 |
and(bits) | Bitwise and | 123 and 456 |
or(bits) | Bitwise or | 123 or 456 |
xor(bits) | Bitwise xor | 0x101 xor 0x010 |
inv() | Bitwise inversion | 123.inv() |