6.2w+
社区成员
char c = (char)-1 & 0xFF;
char d = (char)-1;
System.out.println((int)c);
System.out.println((int)d);
0xFF is hexidecimal, you can Wikipedia that part.
FF is a representation of
00000000 00000000 00000000 11111111
(a 32-bit integer)
& means bit-wise "and", and so when you use it on two ints, each pair of bits from those two ints is and-ed and the result is placed in the resultant int:
Example (showing 16 bits only)
0101 1100 1010 1100
&0000 0000 1111 1111
-----------------
=0000 0000 1010 1100
So as you can see, 0xFF is often used to to isolate a byte in an integer, by truncating the integer to one byte's worth of 1's.
For more information, see this WP article: