As seen another question in 0xFF0000FF An integer literal does not conform to the expected type kotlin.Int
I declaring value 0xFF as Byte
val b:Byte = 0xFF
receiving The integer literal does not conform to the expected type Byte compile error
Since I have clue about kotlin.Byte
is signed byte
How to declaring Byte in Kotlin with 0x00
- 0xFF
unsigned byte just like .net Byte b = 0xFF
?
.
.
If you want instant compiler for testing and answer:
rextester , try.kotlinlang.org
Kotlin doesn't automatically convert between number types.
If you do val b:Byte = 0xFF.toByte()
then it compiles and results in a byte with value -1
.
If you want to hold the unsigned byte value then you need to store it as a Char
, but you will need to convert it to another type to print it as a number:
val b = 0xFF.toChar()
println(b.toInt())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With