Java Bitwise operators

Source: Internet
Author: User

Bitwise operators

All data in Java is performed in the form of binary data, that is, if it is an int variable, the bitwise operation must be transformed into binary data;

The result of a bit binary with, or, XOR, or operation is as follows:

 Package com.test;  Public class Test {    publicstaticvoid  main (string[] args) {        int x = 3;         int y = 6;         & y);        | y);         ^ y);}    }

Running Result: 2,7,5

In the computer's data representation only defines a positive number representation, and does not define a negative number representation, so, negative numbers are generally used in the form of complement , positive number of the original code, anti-code, and complement are the same, negative anti-code is in addition to the sign bit is 1, the other bits are reversed, complement is "Anti code +1"

 Package com.test;  Public class Test {    publicstaticvoid  main (string[] args) {        int x =-3;        System.out.println (~x);    }}

Operation Result: 2

Java Bitwise 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.