Approaches to Convert to/from Longs in Kotlin JS


I am using a third party JS library that creates longs the same way Kotlin has them, with two fields that are high and low bits. But Kotlin doesn’t expose these two values outside of their JS impl. I essentially need both the constructor and access to the high and low bits from Is this a reasonable request and worthy of an issue? In the meantime, what is the best way to do this, even in a hacky way?


You should be able to expose those functions like this

fun Long.Companion.fromBits(lowBits: Int, highBits: Int): Long 
    = js("Kotlin").Long.fromBits(lowBits, highBits) as Long


Yeah, that’s what I’ll do and getHighBits/getLowBits in the other direction. I fear it may change out from under me though but oh well.


Well the js source of this was never edited before (except for added copyright) so I think you are safe.