Is there a way in Kotlin to explicitly declare a `...
# announcements
s
Is there a way in Kotlin to explicitly declare a
Byte
or
UByte
literal? I know that
val toto: UByte = 128u
works when it's an assignment, but I'm looking to make something like this compile:
Copy code
while (myUByteArray[index] and 128u == 128u) {
}
without having to do an explicit cast like
128u.toUByte()
. Thanks! EDIT: According to https://kotlinlang.org/docs/tutorials/kotlin-for-py/primitive-data-types-and-their-limitations.html, I can't without an explicit conversion. I think I will just put the
128u
into a local
val
.
d
I would go with
myUByteArray[index].toUInt()
And compare with
0x80u
Are you trying to read a varint? :)
s
Yeah, something similar to a varint from a protocol buffer encoding. But I settled with a private UByte constant of 128u (or 0x80u).