Join Slack
I have a ByteBuffer reading a binary file with values as UInt32 . How do I read that in kotlin?
# announcements
b
bjonnh
04/29/2020, 6:53 PM
I have a ByteBuffer reading a binary file with values as UInt32 . How do I read that in kotlin?
bjonnh
04/29/2020, 6:54 PM
in java people do bb.getInt() & 0xFFFFFFFFL
bjonnh
04/29/2020, 6:54 PM
but that doesn't work in kotlin (wants both sides to be of the same type)
bjonnh
04/29/2020, 7:01 PM
I also can't do that with bytes:
bjonnh
04/29/2020, 7:01 PM
(in java) (((b[3] & 0xff) << 24) | ((b[2] & 0xff) << 16) | ((b[1] & 0xff) << 8) | (b[0] & 0xff));
s
serebit
04/29/2020, 7:17 PM
and
serebit
04/29/2020, 7:18 PM
alternatively, do
getInt
and convert it to a
UInt
, then & it with the constant (also as an unsigned int)
b
bjonnh
04/29/2020, 11:10 PM
of 0xffu is a thing now as well
6
Views
Open in Slack
Previous
Next
kotlinlang
A modern programming language that makes developers happier.
Powered by