August 2018
Beginner
178 pages
4h 56m
English
Kotlin doesn't have operators for the bitwise manipulation of integers. Bitwise operations in Kotlin are done with functions. The following table shows all bitwise manipulation functions:
|
Function |
Operation |
|
shl(bits) |
signed shift left (<< in Java) |
|
shr(bits) |
signed shift right (>> in Java) |
|
ushr(bits) |
unsigned shift right(>>> in Java) |
|
and(bits) |
bitwise and ( & in Java) |
|
or(bits) |
bitwise or ( | in Java) |
|
xor(bits) |
bitwise xor (^ in Java) |
|
inv() |
bitwise inversion |
These are infix functions so we can call them without parentheses. This is how you'd shift by one bit to the right:
val n = 8 shr 1
Read now
Unlock full access