The operand is evaluated and then converted to a 32-bit integer value. Every bit is complemented and the result is a bitwise NOT.
The truth table shows the result of this operator for a Boolean primitive value:
This operation is applied to each individual bit in the operand, inverting them one by one.
Note that this could be classified as a unary operator but here we have called it a bitwise operator on account of its functionality rather than its placement.
The associativity is right to left.
Refer to the operator precedence topic for details of execution order.
There are some deficiencies in the handling of bitwise operators in the MSIE 5.0 browser on the Macintosh platform. It does not properly handle the sign bit and so you should observe some caution when using this operator.
<HTML> <HEAD></HEAD> <BODY> <SCRIPT> myValue1 = 0xFFFF; myValue2 = ~myValue1 document.write("Val 1 : " + binary32(myValue1) + "<BR>"); document.write("NOT : " + binary32(myValue2) + "<BR>"); // Binary convertor (ignore sign bit on MSIE) function binary32(aValue) { myArray = new Array(32); for(myEnum=0; myEnum<32; myEnum++) { if(aValue & Math.pow(2, myEnum)) { myArray[31-myEnum] = "1"; } else { myArray[31-myEnum] = "0"; } } return myArray.join(""); } </SCRIPT> </BODY> </HTML>
Prev | Home | Next |
Bitwise expression | Up | Bitwise operator |
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. |