Correlation operations of binary operators

Source: Internet
Author: User

Binary operators, often forget, so hang on the blog for easy reference later.
Note: The binary of 1 is 00 ... 00001, 0 of the binary is 000 ..... 0000.3 of the binary is 00 ... 00011, 5 of the binary is 00 .... 00101

1. Bitwise AND operator (&)

Rule: 0&0 = 0, 0&1 = 0, 1&1=1. That is, two bits are 1 at the same time, the result is 1, otherwise 0
Example: 3 & 5 = 1. (000011 & 000101 = 000001)

2. Bitwise OR operator (|)

Rule: 0|0 = 0,1|0 = 1,0|1 = 1,1|1 = 1 The two bits of the participating bit operation as long as there is a 1, then 1
Example: 3 | 5 = 7 (0000011 | 00000101 = 0000111)

3. Xor operator (^ also called XOR (Will encounter XOR, which is XOR))

Rule: 0^0 = 0,0^1=1,1^0=1,1^1=0 The two bits of the bit operation as long as the same is 0, the difference is 1
Example: 3^5 = 6 (00000011^00000101=00000110)
The special arbitrary number ^ 0 = any number.

4. Take the inverse operator (~)

Rule: bits 0 becomes 1, 1 becomes 0

5. Shift Left (<<)

Rule: the equivalent of multiplying by 2

6. Move right (>>)

Rule: equivalent to dividing by 2

Correlation operations of binary 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.