Tag: 位移

Kotlin`shl`不工作

我试图将shl应用于Kotlin中的Int值: val a = 1092455 println(a.toString()) println(toString(bits(one))) println(toString(bits(one shl 16))) println(toString(bits(one shr 16))) 这会产生以下输出: 1092455 0000000000010000 1010101101100111 0000000000000000 0000000000000000 0000000000000000 0000000000010000 正如你所看到的, shr正确的结果是最左边的16位( 0000000000010000 )被移到右边,但是shl没有给出预期的输出( 1010101101100111 0000000000000000 )。 我错过了什么? 编辑: bits方法: fun bits(value: Int): BooleanArray { var x = value.toDouble() val result = BooleanArray (32) for (i in 31 downTo 0) { val d = […]

科特林位移

我想转换代码如果这个答案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); } 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 […]