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 PMByteJoffrey
07/04/2022, 1:52 PMJoffrey
07/04/2022, 1:53 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.Sam
07/04/2022, 2:14 PMJoffrey
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 byteSam
07/04/2022, 2:23 PMbyte 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 255Joffrey
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())Sam
07/04/2022, 2:30 PMdata.toUByte().toInt() if you want to match the Java version more exactly)