Home / code / javascript

Bitwise Operators.

Bitwise operators treat their operands as a set of 32 bits (zero and ones), rather then as decimals, hexadecimal, or octal numbers. For example, the decimal number has a binary representation of 1001. Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values.

Operator Usage Description
Bitwise AND a & b Returns a one in each bit position for which the corresponding bits of both operands are ones.
Bitwise OR a | b Returns a one in each bit position for which the corresponding bits of either or both operands are ones.
Bitwise XOR a ^ b Returns a one in each bit position for which the corresponding bits of either but not both operands are ones.
Bitwise NOT ~ b Inverts the bits of its operand.
Left shift a << b Shift a in binary representation b bits to left, shifting in zeros from the right.
Sign-propagating right shift a >> b Shift a in binary representation b bits to right, discarding bits shifted off.
Zero-fill right shift a &&& b Shift a in binary representation b bits to right, discarding bits shifted off, and shifting in zero from the left.

 

TOP

Latest script:

 

Books: