How can i safely pass long from c to kotlin as int...
# kotlin-native
b
How can i safely pass long from c to kotlin as int ir int array and then safely convert it back to long on kotlin?
b
How do you split your long to int?
c
Using my library you can use something likee this:
Copy code
fun Long.toInts() =
            Int.fromBytes(this[0],this[1],this[2],this[3]) to
            Int.fromBytes(this[4],this[5],this[6],this[7])
Also, if you don't want to use my library you can use something like this:
Copy code
fun Long.toInts():Pair<Int,Int>{
        val b1=((this ushr (56 - 8 * 0)) and 0xFF).toByte()
        val b2=((this ushr (56 - 8 * 1)) and 0xFF).toByte()
        val b3=((this ushr (56 - 8 * 2)) and 0xFF).toByte()
        val b4=((this ushr (56 - 8 * 3)) and 0xFF).toByte()
        val b5=((this ushr (56 - 8 * 4)) and 0xFF).toByte()
        val b6=((this ushr (56 - 8 * 5)) and 0xFF).toByte()
        val b7=((this ushr (56 - 8 * 6)) and 0xFF).toByte()
        val b8=((this ushr (56 - 8 * 7)) and 0xFF).toByte()

        val int1 = ((b1.toInt() and 0xFF) shl 24) +
                ((b2.toInt() and 0xFF) shl 16) +
                ((b3.toInt() and 0xFF) shl 8) +
                ((b4.toInt() and 0xFF) shl 0)

        val int2 = ((b5.toInt() and 0xFF) shl 24) +
                ((b6.toInt() and 0xFF) shl 16) +
                ((b7.toInt() and 0xFF) shl 8) +
                ((b8.toInt() and 0xFF) shl 0)
        return int1 to int2
    }