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

diesieben07

08/08/2017, 3:35 PM
No reason to re-implement all that stuff yourself. There are good solutions for reading primitive values from a byte stream. NIO `ByteBuffer`s are one, there is
ByteArrayDataInput
from Guava, etc.
m

manuell

08/08/2017, 4:11 PM
About Guava, Are there real benefits using unsignedBytes instead of simply promoting byte to int? I've to work with a lot of unsigned values
d

diesieben07

08/08/2017, 4:36 PM
Well, there is a difference.
0xFF.toByte().toInt() == -1
But
UnsignedBytes.toInt(UnsignedBytes.checkedCast(0xFF)) == 255
.
m

manuell

08/09/2017, 11:18 AM
Well, 0xFF.toByte().toInt() and 0xFF == 255
d

diesieben07

08/09/2017, 11:19 AM
No,
0xFF.toByte().toInt() == -1
.
m

manuell

08/09/2017, 11:32 AM
Yes, but You've to add a bitwise AND
d

diesieben07

08/09/2017, 11:32 AM
Yes, which is what
UnsignedBytes
does.