我找到了java的解决方案:
public byte getBit(byte value, int position) {
return (value >> position) & 1;
}
Run Code Online (Sandbox Code Playgroud)
但是在 Kotlin 中是怎样的呢?
Kotlin 的等价物是:
fun getBit(value: Int, position: Int): Int {
return (value shr position) and 1;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
262 次 |
| 最近记录: |