Bitwise operators convert both operands to 32 bit integers and apply the operator to them on a bit-by-bit basis.
Here is a table of all operators in the bitwise category and those that are members of other categories but perform bitwise operations:
Op | Description |
---|---|
~ | Bitwise complement (NOT) |
& | Bitwise AND |
<< | Bitwise left shift |
>> | Bitwise right shift |
>>> | Bitwise right shift (unsigned) |
| | Bitwise inclusive OR |
^ | Bitwise XOR (exclusive OR) |
&= | Bitwise AND and assign to an LValue |
|= | Bitwise inclusive OR and assign to an LValue |
^= | Bitwise exclusive XOR and assign to an LValue |
<<= | Bitwise shift left and assign to an LValue |
>>= | Bitwise shift right and assign to an LValue |
>>>= | Bitwise shift right (unsigned) and assign to an LValue |
The result of a bitwise expression is a 32 bit binary value and should not be confused with the Boolean value returned by a logical operator.
The bitwise operators may yield a value that in other languages is the same as the logical operator. However although in C language, true and false are really integer values, in JavaScript the Boolean and Number values are distinctly different types.
Be careful to use the correct number of ampersands and vertical bars to select the bitwise of the operator. Refer to the Logical operator topic for a list of operators to avoid in bitwise expressions.
ECMA 262 edition 2 - section - 11.10
ECMA 262 edition 3 - section - 11.10
Wrox Instant JavaScript - page - 19
Prev | Home | Next |
Bitwise NOT - complement (~) | Up | Bitwise OR (|) |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |