Kotlin:如何从 Byte 中获取某个位置的某个位的值?

bru*_*max 1 kotlin

我找到了java的解决方案:

public byte getBit(byte value, int position) {
   return (value >> position) & 1;
}
Run Code Online (Sandbox Code Playgroud)

但是在 Kotlin 中是怎样的呢?

Ste*_*eve 5

Kotlin 的等价物是:

fun getBit(value: Int, position: Int): Int {
    return (value shr position) and 1;
}
Run Code Online (Sandbox Code Playgroud)