reactormonk
07/04/2022, 1:47 PMx and 0xFF.toByte()
a noop? Aka x and 0xFF.toByte() == x
is always true?Joffrey
07/04/2022, 1:49 PMx
?reactormonk
07/04/2022, 1:50 PMByte
Joffrey
07/04/2022, 1:52 PMInt
to do this š¤·reactormonk
07/04/2022, 1:53 PMJoffrey
07/04/2022, 1:54 PMSam
07/04/2022, 2:13 PM& 0xFF
would be used to truncate the sign bits or other unwanted extras. Translating it to Kotlin probably requires some understanding of the intended behaviour.Joffrey
07/04/2022, 2:16 PMresponse.getData()[0]
is already a byte, though. I'm not sure what the Java code wanted to do initially with thisSam
07/04/2022, 2:21 PMJoffrey
07/04/2022, 2:22 PM& 0xFF
(even in terms of sign bits) if the original value is a byteSam
07/04/2022, 2:22 PM0xFF
in Java is an int, because it is too big to be a signed bytebyte signed = -1;
System.out.println("Signed value is " + signed);
// Signed value is -1
int unsigned = 0xFF & signed;
System.out.println("Unsigned value is " + unsigned);
// Unsigned value is 255
Joffrey
07/04/2022, 2:24 PM& 0xFF
also converts the original value to int
before truncating the bitsSam
07/04/2022, 2:28 PMval data: Byte = -1
println("Signed value is " + data)
println("Unsigned value is " + data.toUByte())
data.toUByte().toInt()
if you want to match the Java version more exactly)