C # not commonly used logical operators

Source: Internet
Author: User

&, ^, | Operators are called logical operators. Operators are used to connect computing objects with the C # syntax. Operators are called logical expressions. Logical operator "!" And "^" only act on the subsequent operands, so it is called The unary operator.

These three operators are used in expressions to generate a logical value of true or false.

The operations of logical operators on Expressions A and B are shown in the following table.

Logical operator running result

A

B

A & B

A | B

A ^ B

<

>

False

False

False

False

False

Left Shift

Right Shift

False

True

False

True

True

-

-

True

False

False

True

True

-

-

True

True

True

True

False

-

-

|The result is false only when both operands are false.&True is returned only when both operands are true.^True is returned only when only one operand is true.~Operators perform bitwise complement operations on the operands. The result is equivalent to reversing each bit.

<And> convert the number to be displaced to binary for parallel displacement.

Example:

Decimal: 3 | 2 = 3; 3 & 2 = 2; 3 ^ 2 = 1; 13> 1 = 6; 13 <1 = 26

Binary representation: 11 | 10 = 11; 11 & 10 = 2; 11 ^ 10 = 1, that is, the calculation result on the table by bit

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.