+ 3
What is the difference between ( | )and ( || )
3 Réponses
+ 9
|| is a logical OR operator which returns either True or False
| is a bitwise operator
for example, take the numbers 2 and 5.
their bit representations are:
2: 010
5: 101
the bitwise operator takes every corresponding bits of the same column and perform an OR operation.
so in the example above we get:
2: 010
5: 101
x: 111
and 111 in binary is 7, thus, x is 7
+ 3
|=Bitwise ||=OR
+ 2
| is bitwise or. And || is a logical or operator. | is operated on bits, it returns 1 if any of the two compared bits is 1. || is operated on conditions, it returns true if any of the condition is true.