JavaScript Bitwise Operators - Javascript Operator

Javascript examples for Operator:Bitwise Operator

Introduction

Bit operators work on 32 bits numbers.

Any numeric operand in the operation is converted into a 32 bit number.

The result is converted back to a JavaScript number.

Operator Description ExampleSame as Result Decimal
&AND x = 5 & 1 0101 & 0001 0001 ?1
|OR x = 5 | 1 0101 | 0001 0101 ?5
~NOT x = ~ 5?~0101 1010 ?10
^XOR x = 5 ^ 1 0101 ^ 0001 0100 ?4
<< Left shift x = 5 << 1 0101 << 1 1010 ?10
>> Right shift x = 5 >> 1 0101 >> 1 0010 ? 2

Related Tutorials