JavaScript Bitwise Operators

Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.

Operator

Description

Example

Same as

Result

Decimal

&

AND

5 & 1

0101 & 0001

0001

1

|

OR

5 | 1

0101 | 0001

0101

5

~

NOT

~ 5

~0101

1010

10

^

XOR

5 ^ 1

0101 ^ 0001

0100

4

<<

Zero fill left shift

5 << 1

0101 << 1

1010

10

>>

Signed right shift

5 >> 1

0101 >> 1

0010

2

>>>

Zero fill right shift

5 >>> 1

0101 >>> 1

0010

2

The examples above uses 4 bits unsigned examples. But JavaScript uses 32-bit signed numbers.
Because of this, in JavaScript, ~ 5 will not return 10. It will return -6.
~00000000000000000000000000000101 will return 11111111111111111111111111111010