This article from: http://www.cnblogs.com/GT_Andy/archive/2010/03/30/1921805.html
The results are the same (for the respective operands), but there is a difference in performance.
&& | | : Logical operators
& and |: Bitwise operators
&& is meant to be, and a&&b both are true.
|| Yes or mean, a| | b There is one truth and that is true.
&,| is a bitwise operator. That is, the bitwise operation,
such as 00000011 & 00000001=00000001
for (&&,| |), the object of the operation is a logical value, that is, the True/false
operation results in only the following four cases.
true && true = True
true && false = False
false && true = false< Br>false && false = False
true | | true = True
true | | False = True
False | | true = True
False | | False = False
for (&,|), the object of the operation is a bit, that is, the result of the 1/0
operation is only the following four cases.
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0
1 | 1 = 1
1 | 0 = 1
0 | 1 = 1
0 | 0 = 0
&& and & the result is the same for their respective operands.
Similarly, | | and | is the same.
For example: The result of the 5&&2 operation is treated like this.
First 5, nonzero, which is true
2, nonzero, true ,
True&&true = True
The result is true. The whole process of operation needs to be transformed. The binary direct comparison of operands is not directly used. So the results are different. At the time of comparison, true should be converted to a binary value like 11111111, false may turn into 00000000. The
is the same here, that is, for an operand.
&& 's operand is true/false regardless of what type of expression you are using, he first converts to one of the true/false before participating in the operation.
& Operand is 0/1, do not need to convert, how many bits directly to calculate the number of bits on it.
Links and differences between && and | |,& and | In the c,c#,c++