How does & calculate in Java

Source: Internet
Author: User
& Similarities: "and" operation. The "and" here and the "and" in mathematics are of the same meaning and follow the "One false is required" principle. That is, if one element on both sides of the "and" symbol is false, the result after the "and" operation is executed is false. & Differences: 1) & indicates "bitwise AND". Here "bit" refers to binary bit (BIT ). For example, convert decimal digit 8 to binary: 1000; Convert digit 9 to binary: 1001. If the followingProgram: Public class test {public static void main (string [] ARGs) {system. out. println (9 & 8) ;}} the output result should be: 8 cause: 1001 & 1000 = 1000. Generally, 1 indicates true in the computer, and 0 indicates false. 1 & 1 = 1 on the leftmost side, 1 & 0 = 0.2 on the rightmost side) & indicates the logic "and", that is, the Boolean value in Java can exist on both the left and right sides of the & symbol. True & false = false, true & True = true, still "a false is required ". Note that the & symbol has the so-called "Short Circuit Principle". When a & B appears, if A is determined to be false, then expression B will not be given the opportunity to execute or be judged. The result is false. Note: For decimal and binary conversion, every four bits can follow the "8421" principle. 1001 means 8 + 1 = 9, means 8 + 2 + 1 = 11.

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.