Java Learning materials-logic and, bitwise AND

Source: Internet
Author: User

logical AND, bitwise AND

& and the && can be used as the logical AND operator, representing the logical and ( and ) , the result of the entire operation is true when the result of an expression on either side of the operator is true, otherwise, theresult is false,as long as there is a side of false.

&& also features a short-circuit , that is, if the first expression is false, the second expression is no longer evaluated, for example, for an if (str! = null &&!str.equals (")) expression, when a when str is null , subsequent expressions do not execute, so the nullpointerexception does not appear if you change && to & , you will throw NullPointerException exception. if (x==33 & ++y>0) y grows,if (x==33 && ++y>0) does not grow

& can also be used as a bitwise operator , when an expression on either side of the & operator is not of type Boolean,& represents bitwise AND operation, we typically use 0x0f to do with an integer & operation to get the minimum 4 bit bits of the integer , for example,0x31 & 0x0f The result is 0x01.

&&is logical AND

that is , whether the expression on both sides of the && is true or not, this && expression value is true

&is bitwise AND

1&1=1; 1&0=0; 0&1=0; 0&0=0

The number of both sides of the & will be expanded with binary, each seeking and computing (binary and operation, with logic and almost ), thelast obtained binary number is the result; logic and results are only true and false, And the bitwise and the result is a real number


Java Learning materials-logic and, bitwise AND

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.