Basic knowledge Operators for Java

Source: Internet
Author: User

A Operator. 1. Arithmetic operator: +,-, *,/,%2. Self-increment: + +,--

+ + is evaluated before the assignment

+ + after assigning the value after the operation

-Minus minus.

3. Assignment operator: =, +=,-=,*=,/=4. Relational operator: >,<,>=,<=,==,!=5. Logical operators: &, | ,! ,&&, | | 6. Bitwise operators: (1). The symbol for the bitwise operator:

& (with): Both are 1 when I am one, the others are 0

| (OR): Both are 0 o'clock to 0, and the others are 1.

^ (XOR): The difference between the two is 1, the same as 0

~ (Inverse): 0 becomes 1, 1 becomes 0.

(2). Negative representation: The highest bit of bits is 1, then this number is a negative.

-1:1111-1111 1111-1111 1111-1111 1111-1111

0:0000-0000 0000-0000 0000-0000 0000-0000

-2:1111-1111 1111-1111 1111-1111 1111-1110

-3:1111-1111 1111-1111 1111-1111 1111-1101

-4:1111-1111 1111-1111 1111-1111 1111-1100

-5:1111-1111 1111-1111 1111-1111 1111-1011

-6:1111-1111 1111-1111 1111-1111 1111-1010

-7:1111-1111 1111-1111 1111-1111 1111-1001

7:0000-0000 0000-0000 0000-0000 0000-0111

Rule: Negative number corresponding to the positive number-1, the inverse negative number corresponding to the positive number reversed +1

(3). Shift Operator: operation on Bits

>> Right Shift

<< left Shift

>>> Unsigned Right Shift

Move right:

System.out.println (6>>1); --->3 6/2 2*1

System.out.println (6>>2); --->1 6/4 2*2

System.out.println (6>>3); --->0 6/8 2*3

System.out.println ( -6>>1); -6/2-->-3

Rule: Shift the number of digits to the right by dividing by 2 how many times you need to move. Move Left:

System.out.println (6<<1); --->12 6*2 2*1

System.out.println (6<<2); --->24 6*4 2*2

System.out.println (6<<3); --->48 6*8 2*2*2

System.out.println (6<<4); ---->96 6*16 2*2*2*2

System.out.println ( -6<<2);//--->-24

//Law: How many digits to the left, multiply this number by 2 times. >>> unsigned Right shift feature: No matter if your highest bit is 0 or 1, the vacancy is 0.

System.out.println (6>>>1); 3

System.out.println (6>>>2); 1

System.out.println ( -6>>>2); 1073741822

Function: Increase the operation rate. Bit arithmetic is the fastest execution. Features: A number A and two the same number ^, the final result is still the original number A.

Basic knowledge Operators for Java

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: info-contact@alibabacloud.com 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.