What are the bit operators supported by C #
This article mainly explains "what bit operators C#supports", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "what bit operators C#supports"!
bitwise operators
Bitwise operators act on bits and perform operations bitwise.&, | The truth table for and ^is as follows:
pqp & qp | qp ^ q00000010111111010011
Suppose if A = 60 and B = 13, now expressed in binary format, they are as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
The following table lists the bit operators supported by C#. Assuming variable A has a value of 60 and variable B has a value of 13, then:
Operator Description Instance & Binary AND operator copies one bit into the result if present in both operands. (A & B) will get 12, which is 0000 1100| The binary OR operator copies one bit into the result if present in either operand. (A |B) will result in 61, which is 0011 1101^If present in one of the operands but not both, the binary XOR operator copies one bit into the result. (A ^ B) will result in 49, which is 0011 0001~ The bitwise negation operator is a unary operator with a "flip" bit effect, i.e. 0 becomes 1 and 1 becomes 0, including the sign bit. (~A ) will result in-61, which is 1100 0011, a signed binary complement.> 2 will get 15, that is, 0000 1111 to this, I believe everyone has a deeper understanding of "what bit operators C#supports", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!