Java 0 Basic Series 004--operators

Source: Internet
Author: User
Tags bitwise

The most basic operators are familiar with the + 、-、 *,/, which are binocular operators
Logical operators && (logic and), | | (logical OR),! (logical) is an operator that operations on a Boolean type, where &&, | | | It's the eyes, it's monocular.
A&&b as long as a, b any one variable is false, the result of the operation is false, no is true
a| | As long as any one of the B is true, the budget result is true.
!a, when a is true the result of the operation is false and the result of the operation is true when a is false

Bitwise operator ~ (take No), & (Bitwise AND), | (bitwise OR), ^ (XOR) is a bitwise operator
such as the a=001,~a operation will become 110;&, |, ^ are binocular operators
Any one of the & operators is 0, the result is 0, otherwise 1, such as a=1001,b=1000, the result of A&b is 1000
Any one under the | operator is 1, the result is 1, otherwise 0, such as a=1001,b=1000, the result of A&b is 1001
Under the ^ operator, the two bit values are the same, the result is 1, otherwise 0, such as a=1001,b=1000, the result of A&b is 1110

>> (Shift right) \<< (left), shift left is equal to multiply by 2, left 1 is multiplied by one 2. Shift right is equivalent to dividing by 2, moving one right by one and dividing by a 2.

Extension operators
A + = B equates to A=a+b
A-= B is equivalent to A=a-b
A *= B is equivalent to A=a*b
A/= B is equivalent to a=a/b

String connector +, two strings with a + symbol, the role of + becomes the connection of two strings

Trinocular operator
The logic of writing? A:B, when logic is true, the result of the operation is a. When logic is false, the result of the operation is B

//operator Public classOperator { Public Static voidMain (string[] args) {intA = 1,b = 2; System.out.println ("a+b=" +a+b);//addition Operation                Booleanc =false, d =true; System.out.println ("C&&d=" + (c&&d));//Logic and Operations//Decimal for Binary 1000 decimal is 8,1001 9        intE = 8&9; System.out.println ("1000&1001=" +integer.tobinarystring (e));//bitwise operator, tobinarystring turns the result into binary so we could see                    intf = 2<<3;//displacement Operation 2<<3 equivalent to 2*2^3System.out.println ("2<<3=" +f); intg = 1<2?5:6;//Three mesh operator, the result of 1<2 logic is true, so the result of the operation is 5System.out.println ("1<2?5:6=" +g); }}

Run results

Java 0 Basic Series 004--operators

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.