The key is that the hex literal 0xFF is still an int..that is, it takes up 32 bits. That makes it look like this in binary:
00000000 00000000 00000000 11111111
When you do a bitwise AND with this value, it is going to mask all but the lowest 8 bits of the number.
InputStream.read() always returns an int, in the range of 0-255, UNLESS the end of the stream was reached, in which case it returns -1.
In binary, 0 is, well, all zeros, and 255 looks like this:
00000000 00000000 00000000 11111111
But a -1 looks like this
11111111 11111111 11111111 11111111
When you do a bitwise AND of 0xFF and any value from 0-255, the result is the exact same as the value. However, if you do:
-1 & 0xFF
you get
00000000 00000000 00000000 11111111, which does NOT equal the original value of -1.
SO that is why they say that method will only return false when the value returned by the call to read() is -1, signifying the end of the stream.
ALSO, note you have a typo in your method. The return statement should read:
return value == (value & 0xFF);
Note the use of the EQUALITY, not the ASSIGNMENT operator.
Your syntax as written works for C++ but is illegal in
java.