Bitwise operations: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 1,680: Line 1,680:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>/* for symmetry with Kotlin's other binary bitwise operators
<lang scala>// version 1.0.5-2

/* for symmetry with Kotlin's other binary bitwise operators
we wrap Java's 'rotate' methods as infix functions */
we wrap Java's 'rotate' methods as infix functions */
infix fun Int.rol(distance: Int): Int = Integer.rotateLeft(this, distance)
infix fun Int.rol(distance: Int): Int = Integer.rotateLeft(this, distance)
Line 1,696: Line 1,694:
println("x AND y = ${x and y}")
println("x AND y = ${x and y}")
println("x OR y = ${x or y}")
println("x OR y = ${x or y}")
println("x XOR y = ${x xor y}")
println("x XOR y = ${x xor y}")
println("x SHL y = ${x shl y}")
println("x SHL y = ${x shl y}")
println("x ASR y = ${x shr y}") // arithmetic shift right (sign bit filled)
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 LSR y = ${x ushr y}") // logical shift right (zero filled)
println("x ROL y = ${x rol y}")
println("x ROL y = ${x rol y}")
println("x ROR y = ${x ror y}")
println("x ROR y = ${x ror y}")