Home  >  Article  >  Java  >  What does & mean in java

What does & mean in java

下次还敢
下次还敢Original
2024-04-26 23:33:13750browse

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).

What does & mean in java

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:

  • Logical AND (&&): When both Boolean values ​​are true, return true.
  • Conditional AND (&): Execute the code block only when both boolean values ​​are true.
  • Type check (instanceof): Check whether the object is the specified type or its subclass.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does = mean in javaNext article:What does = mean in java