bitwise operators in Java

Source: Internet
Author: User

Tag: Take reverse XOR HashMap bitwise negation now absolute amp unsigned

Although Java's bitwise operators are seldom used in daily life, it is found that there are >>> operators in the source code of HashMap, and also the bit operations in Java are learned by the way.

First, & and bitwise AND, if the same bit of two binary numbers is 1, then the new binary number obtained is also 1, otherwise 0;

| or bitwise OR, if the two binary numbers have the same bit at least one of 1, then the new binary number obtained is the bit also 1, otherwise 0;

^ XOR Bitwise XOR, if the two binary numbers are the same bit different (one for 11 is 0), then the new binary number obtained is the bit 1, otherwise 0;

~ Not non, with the above three is different: the above is two number bitwise operation to get a new number, ~ is a binary number bitwise negation.

Second, >>, >>> and << shift operators

>> and >>> are right-shift operators, the difference is that >> is signed right shift,>>> number unsigned right shift.

If the number is positive, after the right shift >> and >>> are in the high 0, there is no difference, if the number is negative, after the right shift >> in the high-fill 1,>>> in the high-fill 0.

<< is the left-shift operator.

The number following the symbol indicates the number of bits moved.

Third, add: Original code, anti-code and complement.

The original code, the inverse code and the complement of the positive numbers are the second binary representations;

Negative Number: The original code is the absolute value of the binary representation, and then the sign bit is 1, the anti-code for the sign bit counter, the complement is anti-code plus 1.

The numbers are stored in the form of a complement in the computer.

bitwise operators in 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.