22
I was analyzing some possibilities for the implementation of an algorithm and I went to look up this &
and |
, and I read some topics in English but it’s not 100% clear to me what it’s for and where I can use it. Then I would like an explanation, clearer and with practical examples of how to use it. (And in my native language, in case: Português).
Questions
- What is the difference between operators
&
and&&
? - What is the operator for
&
? - An example of use for the operator
&
? - What is the difference between operators
|
and||
? - What is the operator for
|
? - An example of use for the operator
|
?
Maybe here will be a complete answer on the 4 operators, but for now, this one responds well on the use of
|
and||
.– Paulo Rodrigues
The "double" version would be to manipulate integer values, the "single" version for bit-by-bit logic.
– bpinhosilva
Tip: Make Codecademy Javascript Curse that you get it in a flash (:
– Andrey Hartung
@bpinhosilva not always, see my answer :)
– Math
Right, @Math, but what I meant is that the & operator does the logical execution on the operating bits instead of && that does it on the actual value of the operands.
– bpinhosilva
@bpinhosilva the
&
can also make the comparison in the truth value of operands, say that the&
only makes the logic in bit a bit is wrong.– Math
@Math, maybe my expression wasn’t complete, there’s the difference you quoted in your answer and it’s explained well. I said it’s mostly used for bit-by-bit operation, I didn’t mean it would be "just" for it.
– bpinhosilva