操作符
Kotlin支持标准的数学操作,下面罗列了按位的相关操作函数:
shl(bits) – signed shift left (Java's << )
shr(bits) – signed shift right (Java's >> )
ushr(bits) – unsigned shift right (Java's >>> )
and(bits) – bitwise and
or(bits) – bitwise or
xor(bits) – bitwise xor
inv() – bitwise inversion(转向)
val x = (1 shl 2)
val y = (8 shr 2)
val z = (0xFFFF ushr 31)
val a = 1 and 2
val b = 1 or 2
val c = 1 xor 2
val d: Int = 11
val e: Int = d.inv()