These operators work with 32-bit integers. That is, they convert their operands to 32-bit integers and produce a result that is a 32-bit integer (encoded as a floating point number, at least externally).
parseInt(str, 2) parses a string str in binary notation (base 2). For example:
> parseInt('110', 2) 6num.toString(2) converts the number num to a string in binary notation. For example:
> 6..toString(2) '110'
> (parseInt('11001010', 2) & parseInt('1111', 2)).toString(2) '1010'Bitwise Or: number1 | number2
> (parseInt('11001010', 2) | parseInt('1111', 2)).toString(2) '11001111'Bitwise Xor (eXclusive Or): number1 ^ number2
> (parseInt('11001010', 2) ^ parseInt('1111', 2)).toString(2) '11000101'There are two ways to intuitively understand binary bitwise operators.
First explanation: one boolean operation per bit. In the formulas below, ni means bit i of number n interpreted as a boolean (0 is false, 1 is true). For example, 20 is false, 21 is true.
x ^^ y === (x && !y) || (!x && y)
Second explanation: changing bits of number1 via number2.