https://kotlinlang.org logo
#announcements
Title
# announcements
t

tekjar

11/30/2017, 8:18 AM
Hi. How do I typecast
Byte
to
Int
.
FF
should result to value 255
p

Pavlo Liapota

11/30/2017, 8:20 AM
.toInt()
t

tekjar

11/30/2017, 8:22 AM
toInt() converts
FF
to
-1
j

jstuyts-squins

11/30/2017, 8:22 AM
x.toInt() and 0xFF
Conversion to a larger integer performs sign extension. The
and
removes the extended sign
t

tekjar

11/30/2017, 8:27 AM
Thanks 🙂
k

karelpeeters

11/30/2017, 8:33 AM
If you use this often you can write an extension funtion for it:
Byte.toPositiveInt() = this.toInt() and 0xFF
.