Kotlin移位

Jan*_*tze 2 bit-shift kotlin

如果此答案是Kotlin,我想将代码转换为:https : //stackoverflow.com/a/5402769/2735398

我将此粘贴到Intellij中:

private int decodeInt() {
    return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
            | ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
}
Run Code Online (Sandbox Code Playgroud)

Intellij询问我是否要将其转换为Kotlin,执行此操作时将输出:

private fun decodeInt(): Int {
    return (bytes[pos++] and 0xFF shl 24 or (bytes[pos++] and 0xFF shl 16)
            or (bytes[pos++] and 0xFF shl 8) or (bytes[pos++] and 0xFF))
}
Run Code Online (Sandbox Code Playgroud)

完全0xFF我得到此错误:

The integer literal does not conform to the expected type Byte
Run Code Online (Sandbox Code Playgroud)

通过添加.toByte()之后,我可以消除此错误。

在所有向左移动的操作(shl)中,我都会收到此错误:

Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 

@SinceKotlin @InlineOnly public infix inline fun BigInteger.shl(n: Int): BigInteger defined in kotlin
Run Code Online (Sandbox Code Playgroud)

我无法解决这个问题。。。我对Java / Kotlin中的位移不了解很多。
对此,可以使用的Kotlin代码是什么?

DPM*_*DPM 8

像这样显式转换: 0xFF.toByte()

通常,当您需要有关错误或可能的解决方案的更多信息时,请按Alt + Enter。

左移方法将Int作为参数。因此,同样,将其转换为正确的类型。

(bytes[pos++] and 0xFF.toByte()).toInt() shl 24
Run Code Online (Sandbox Code Playgroud)