Kotlin Programming Cookbook
上QQ阅读APP看书,第一时间看更新

ushr

The ushr function shifts the bit pattern to the right by the specified number of bits, filling the leftmost with 0s.

Here's an example:

fun main(args: Array<String>) {
println( 5 ushr 0)
println( 5 ushr 1)
println( 5 ushr 2)
}

This will output the following:

5
2
1

This is its explanation:

5 = 101 (Binary format)

101 Shift right by 0 bits = 101

101 Shift right by 1 bits = 010 (2 in Decimal)

101 Shift right by 2 bits = 001 (1 in Decimal)