Reputation: 8787
I found this method:
private static int getInt16(ByteBuffer input) {
return ((input.get() & 0xFF) << 8) | (input.get() & 0xFF);
}
What is the purpose of input.get() & 0xFF
? Isn't it the same as input.get()
?
Upvotes: 2
Views: 422
Reputation: 49803
This is pulling bytes (which are 8 bits in size) from input
and combining them into Int16
s, which is what the method returns. The & 0xFF
is insuring that the bytes haven't been sign-extended (which may be unnecessary, but can't hurt).
Upvotes: 2