Bitwise operation

🏷️ Computer science

& (AND)

Return 1 if both compared bits are 1

Return 0 in other cases

| (OR)

Return 1 if there is at least 1 bit

Return 0 if both bits are 0

! (NOT)

Revert 1 to 0 and vice versa

Return a negative number in two’s compliment arithmethic

^(XOR)

Return 1 when there is only a single 1

Shifting operators

>>: shift all bits of a number to the right n times. Fill empty bits in positive number with 0s and negative number with 1s

<<: shift to the left. Empty bits will be filled with 0s


https://hackernoon.com/programming-with-js-bitwise-operations-393eb0745dc4

https://www.cs.uaf.edu/2000/fall/cs301/notes/notes/node45.html

https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html