I'm trying to pack an `Int` as a `Short` in the up...
# announcements
e
I'm trying to pack an
Int
as a
Short
in the upper part of a
Long
, but I get an out of range on declaring an hexadecimal number
Copy code
val l = (value.toLong() shl 48) and 0xffff_0000_0000_0000  // Error:(103, 42) Kotlin: The value is out of range. Expected: Long. Found: Int
How can I solve? Casting to
Long
doesnt help
i
By the way, why do you need 0xFFFF mask here?
e
Just coherence, I need to pack others numbers in the same long in other positions
i
I mean, after shifting value 48 bits left, it seems to be useless zeroing these same 48 bits with the mask
e
I know, but as I said, for coherence and clarity
when I have to pack the next short on side, I do need to anding
0x0000_fffff_0000_0000
d
I think it's an unsigned issue. Why not mask before you shift.
e
also
this did the trick
0xffff_0000_ffff_ffffUL.toLong()