Availability: |
| ||||||||
Property/method value type: | Number primitive | ||||||||
JavaScript syntax: | - | anOperand1 ^ anOperand2 | |||||||
Argument list: | anOperand1 | A numeric value | |||||||
anOperand2 | Another numeric value |
Performs a bit-by-bit XOR of the 32-bit value derived from both operands.
Where a corresponding bit is different in both operands, a 1 bit will be inserted into the result. If the corresponding bit is identical in both operands, regardless of whether they both have a 1 bit or a zero bit, a zero will be inserted at that bit position in the result.
The associativity is left to right.
Refer to the Operator Precedence topic for details of execution order.
This is the truth table for two Boolean primitive values being operated on with the XOR operator.
The bitwise operator performs this operation on each corresponding bit pair in the two operands.
<HTML> <HEAD></HEAD> <BODY> <SCRIPT> myValue1 = 0xFFFF; myValue2 = 0x0FF0; myValue3 = myValue1 ^ myValue2; document.write("Val 1 : " + binary32(myValue1) + "<BR>"); document.write("Val 2 : " + binary32(myValue2) + "<BR>"); document.write("XOR : " + binary32(myValue3) + "<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 unsigned shift right and assign (>>>=) | Up | Bitwise XOR and assign (^=) |
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. |