Java operator summary, java Operator

Source: Internet
Author: User
Tags bitwise operators decimal to binary

Java operator summary, java Operator

1. Arithmetic Operators: +,-, *,/, and % (addition, subtraction, multiplication, division, and remainder)

2. Auto-increment and auto-increment: ++ and ,--

3. assignment operators: =, + =,-=, * =,/=

4. Relational operators: >,<, >=, <=, =, and ,! =

Logical operators: &, |, and ,! , &, |

Bitwise OPERATOR: computes binary bits.

Bitwise operators can calculate decimal integers.

Calculation method: Convert decimal to binary for Calculation

5. Symbols of bitwise operators

& (And): when both are 1, the result is 1, and the others are 0.

| (OR): when both are 0, the result is 0, and the others are 1.

^ (Exclusive or): The difference between the two is 1, and the same is 0.

~ (Reverse): 0 to 1, 1 to 0.

Negative number: the highest bit of binary is 1.

Rule: positive number-1 corresponding to a negative number. The positive number corresponding to the negative number + 1.

Role: encrypt data.

6. Shift Operator: operate binary bits

(1) Left Shift Operator

Common Format: 3 <1

Rule: discard the highest bit, 0 to fill in the second bit

If the number of shifted digits exceeds the maximum number of digits of this type, the compiler will modulo the number of shifted digits. For example, if int type is used to move 33 bits, it actually moves 1 bits.

Calculation rules:

Move all digits to the left according to the binary, remove the digits from the upper position, and add 0 to the lower position.

When the number of operations to the Left shift is int type, the 32-bit value of each operation will be removed and discarded.

When the number of left-shifted operations is of the long type, the 64-bit value of a left-shifted operation will be removed and discarded.

When the number of left-shift operations is of the byte and short types, these types are automatically extended to the int type.

Rule: multiply the number of places to the left by the power of 2.

(2) Right Shift Operator

Common Format: 3> 1

Rule: The symbol bit remains unchanged. Add the symbol bit on the left.

Move all the numbers to the right according to the binary value, and remove the numbers from the low position. Fill the sign bit in the high position, fill 0 in the positive number, and fill 1 in the negative number.

Calculation rules:

When the right-shift operators are byte and short types, these types are automatically extended to int type.

Rule: divide the number of places to the right by the power of 2.

(3) unsigned right shift

Common Format: 3 >>> 1

The extension of the symbol bit is ignored. The value 0 is the maximum bit, which is meaningful only for the 32-bit and 64-bit values.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.