How can I port ``` byte b1 = (byte) 0xAD; byte b2 ...
# announcements
j
How can I port
Copy code
byte b1 = (byte) 0xAD;
byte b2 = (byte) 0xCA;
short s = (short) (b1<<8 | b2);
m
Copy code
val b1 = 0xAD.toByte()
val b2 = 0xCA.toByte()
val s = (b1.toInt() shl 8 or b2.toInt()).toShort()
👍🏽 1
l
bit shifting operators are only available on
Long
and
Int
. Java casts byte and shorts at compilation, but in Kotlin, is has to be explicit