In Java, & is a bitwise AND operator, which compares the binary bits of two integer values bit by bit. Only when both bits are 1, the result bit is 1, otherwise it is 0. Other uses of the & operator in Java include: logical AND (&&), conditional AND (&), and type checking (instanceof).
The meaning of & in Java
& is a bitwise AND operation in Java symbol. It compares the bit-by-bit bits of two integer values (int or long) and returns a new value containing a 1 in the matching bit. The resulting bit is 1 if both bits are 1; otherwise it is 0.
Syntax:
int a = 10; // 二进制表示为 1010 int b = 6; // 二进制表示为 0110 int c = a & b; // 二进制表示为 0010
Result:
c = 2
Because 1010 & 0110 = 0010.
Other uses:
In addition to being used for bitwise AND operations, the & operator also has the following uses in Java:
The above is the detailed content of What does & mean in java. For more information, please follow other related articles on the PHP Chinese website!