Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Bitwise-operations/Kotlin/bitwise-operations.kotlin
Normal file
18
Task/Bitwise-operations/Kotlin/bitwise-operations.kotlin
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
fun main() {
|
||||
// inferred type of x and y is Int (32-bit signed integer)
|
||||
val x = 10
|
||||
val y = 2
|
||||
println("x = $x")
|
||||
println("y = $y")
|
||||
println("NOT x = ${x.inv()}")
|
||||
println("x AND y = ${x and y}")
|
||||
println("x OR y = ${x or y}")
|
||||
println("x XOR y = ${x xor y}")
|
||||
|
||||
// All operations below actually return (x OP (y % 32)) so that a value is never completely shifted out
|
||||
println("x SHL y = ${x shl y}")
|
||||
println("x ASR y = ${x shr y}") // arithmetic shift right (sign bit filled)
|
||||
println("x LSR y = ${x ushr y}") // logical shift right (zero filled)
|
||||
println("x ROL y = ${x.rotateLeft(y)}")
|
||||
println("x ROR y = ${x.rotateRight(y)}")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue