We know that any information is stored in binary form in the computer. Bitwise operators are operators that operate on data in binary order. The bit operators in the C # language are:
& and
| Or
^ XOR or
~ Take the Fill
<< Move Left
>> Move Right
Where the complement has only one operand, while the other bitwise operators have two operands. None of these operations generates an overflow. The operand of the bitwise operator is an integral type or any other type that can be converted to an integral type.
and operation
Operands are operated in binary, and the operation rules are:
0&0=0
0&1=0
1&0=0
1&1=1
This shows that except two digits are 1, and the result of the operation is 1, in any other case and the result of the operation is 0. For example, 2 and 10 are performed with the operation:
Binary representation of 2:00000010
Binary representation of 10:00001010
And operation Result: 00000010
So, the result of 2&10 is 2.
or operation
Operands are performed by bits or by operation, and the rules of operations are:
0|0=0
0|1=1
1|0=1
1|1=1
This shows that except two digits are 0, or the result of the operation is 0, in other cases or the result of the operation is 1. For example, 2 and 10 are performed or calculated:
Binary representation of 2:00000010
Binary representation of 10:00001010
Or operation result: 00001010
So, the result of 2|10 is 10.
XOR or operation
Operands are bits or operated according to the Operation rules:
0^0=0
0^1=0
1^0=0
1^1=1
This shows that when the two phases are at the same time, the difference or operation result is 0, the difference is different or the result of the operation is 1. For example, 2 and 10 perform a different or an operation:
Binary representation of 2:00000010
Binary representation of 10:00001010
XOR Result: 00001000
So, the result of 2^10 is 8.