`java.lang.Long.parseLong()` Why isn't this availa...
# announcements
m
java.lang.Long.parseLong()
Why isn't this available in the Kotlin
Long
?
t
Because "5".toLong() does the job
1
m
Thank you 😄
t
🙂
m
But what about
parseUnsignedLong()
? (I am parsing a binary data stream so I need to differentiate). There is a
.toULong()
but it actually returns an
ULong
which I don't want to use because it's marked as experimental. The Java
parseUnsignedLong()
returns a normal
Long
. I guess I either have to use
ULong
or use the Java method.
d
toULong().toLong()
m
Still makes Idea shout at me for using experimental types but makes my function return the correct type so it will do. Thank you.
j
Mind that a large ULong does not fit inside a Long. (Since it goes further into positive number ranges which it does not need to go into the negative) So if you do that it is maybe just enough to do toLong() and check if number is positive.
d
For numbers larger than Long.MAX_VALUE, they get wrapped around, so ULong.MAX_VALUE == -1 (Long)
m
Yes I parse a string of binary (with radix = 2), checking the number of bits beforehand against
Long.SIZE_BYTES
. Seems to work so far.