The following statements are complete gibberish to me. Can someone explain please?
The bitwise OR (|) operator returns a 1 in each bit position for which the corresponding bits of either or both operands are 1
The bitwise AND (&) operator returns a 1 in each bit position for which the corresponding bits of both operands are 1
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:145.0) Gecko/20100101 Firefox/145.0
Challenge Information:
Working with Unary and Bitwise Operators - What Are Bitwise Operators, and How Do They Work?
bitwise operators work with the binary representation of values
for example, if you have 8 | 10 in binary it would be 1000 | 1100. It says that the operator returns a 1 in each bit position for which the corresponding bits of either or both operands are 1, right? so if we look at the first position, there is a 1 in both, so that makes it a 1 for the result, then second position has a 0 for one and 1 for the other, that makes it a 1, then there is 0 and 0, that makes it a 0, then there is 0 and 0 again, so that’s also a 0, result 1100
Great!
I’d like to explain it as simple as I finally understood it:
Bitwise operators act on each bit of two (or one) given operands,
The AND operator returns 1 in the position only when BOTH bits in the same position are 1;
The OR operator returns 1 the position whenever EITHER or BOTH bits are 1;
The XOR operator returns 1 only if EITHER bit of the operands is 1;
The key is to know if the operand looks for 1 on EITHER or/and BOTH bits.
The rest:
the NOT operator turns 1s into 0s and 0s into 1s, the shift left/right (<</>>) shifts the 1s to the left/right a specified number of times. Hope this helps someone.