I want to convert the code if this answer to Kotlin: https://mcmap.net/q/430222/-using-public-key-from-authorized_keys-with-java-security
I pasted this into Intellij:
private int decodeInt() {
return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
| ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
}
Intellij asks if I want to convert it to Kotlin, when I do this is the output:
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))
}
At all 0xFF
I get this error:
The integer literal does not conform to the expected type Byte
By appending .toByte()
after it I was able to remove this error.
And at all shift left operations(shl
) I get this error:
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
I wasn't able to solve this one...
I don't know a lot about bit shifting in Java/Kotlin...
What would be the working Kotlin code for this?