Bit Operators

Bit operators treat Number types as a 32 bit value, change bits according to the operator and then converts the value back to Number when done. The operators are bitwise NOT (~), AND (&), OR (|), XOR (^), left shift (<<), right shift (>>), unsigned right shift (>>>). All are binary, except NOT which is unary. The dual right shift operators help keep JavaScript portable between different computers and are derived from Java. These operators aren't yet used much in Web-style applications.

a = ~a;    b = b & a;    c = c  >> 3;    d = d >>> 1;

© 1997 by Wrox Press. All rights reserved.