C/b + + binary operators

Source: Internet
Author: User

There are six commonly used binary operators in C + +. Here are a few examples of these six simple introductions and applications.

1. & : with operation. Acting on two binary numbers, it is also possible to manipulate integer data (when both sides of the integer data are automatically converted to binary numbers). Binary is used to set the bit 0 or reset. If two values are binary with, Only if two of the corresponding bits are 1 o'clock on the result bit is 1, the other case is 0. The following:

01011001 & 00101001

The result is: 00001001

2. | : OR operation. and 1 are similar to the operation. Used to merge values. Only if two corresponding bits are 0, the result bit is 0, and all other cases are 1. For example:

01011001 | 00101001

The result is: 01111001

3. ^ : xor operation. This operator occurs when two values are in a single, and the result bit is 0, with a different result of 1. If one is 11, the result bit is 0, 1 is two, or 1 the result bit is 0; for example:

01011001^00101001

The result is: 01110000

4.~ : complement operation. This operator operates on only one binary data, with each bit reversed, that is, 1 becomes 0;0 to 1. For example:

~01011001

The result is: 10100110

The last two are shift operators. These two operators are used to move the bits in a value to the left or right to the number of bits of a particular number. " >>"right-shift operation." <<Move left operation. For example:

01011001>>2 01011001<<2

The result is: 0010110 01100100

The numbers used to fill the empty bits of both ends will vary depending on the operating system, and are generally supplemented with 0.

C/b + + binary operators

Related Article

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.