Bitwise operators of C ++

Source: Internet
Author: User

Bitwise OPERATOR:

The integer operand is considered as a set of binary BITs, which provides the test and setting functions for each bit.

~ : Reverse by bit

<: Shifts left. 1 to 2.

: The right operand identifies the number of digits to move left to generate a new value, discard the removed bits, and insert 0 on the right to supplement the empty space.

>>: Right shift. 1 shifted to/2.

: Its operand identifies the number of digits to be shifted to the right to generate a new value and discard the removed bits.

: If the operand on the right is the unsigned number, 0 is inserted from the left. If the operand is the signed number, the value of the signed bit is inserted or 0.

Note: The right operand of the shift operation cannot be a negative number, and must be a value Strictly less than the number of digits of the left operand. Otherwise it is meaningless.

&: Bitwise AND, if there is 0, the result is 0.

|: Bitwise or, if there is 1, or the result is 1

^: Exclusive or. If two values are different, 1 is used. If the two values are the same, 0 is used.

 

Note: Since the system cannot ensure how to handle the symbol bit of the operand, we recommend that you use the unsigned integer operand.

Bitwise OPERATOR:

The integer operand is considered as a set of binary BITs, which provides the test and setting functions for each bit.

~ : Reverse by bit

<: Shifts left. 1 to 2.

: The right operand identifies the number of digits to move left to generate a new value, discard the removed bits, and insert 0 on the right to supplement the empty space.

>>: Right shift. 1 shifted to/2.

: Its operand identifies the number of digits to be shifted to the right to generate a new value and discard the removed bits.

: If the operand on the right is the unsigned number, 0 is inserted from the left. If the operand is the signed number, the value of the signed bit is inserted or 0.

Note: The right operand of the shift operation cannot be a negative number, and must be a value Strictly less than the number of digits of the left operand. Otherwise it is meaningless.

&: Bitwise AND, if there is 0, the result is 0.

|: Bitwise or, if there is 1, or the result is 1

^: Exclusive or. If two values are different, 1 is used. If the two values are the same, 0 is used.

 

Note: Since the system cannot ensure how to handle the symbol bit of the operand, we recommend that you use the unsigned integer operand.

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.