Home > Java > javaTutorial > body text

What does & mean in java

下次还敢
Release: 2024-04-28 09:50:42
Original
772 people have browsed it

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
Copy after login

Result:

c = 2
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!