Home »
Excel-Built-In-Functions »
Excel-Engineering-Functions »
Excel-Bitxor-Function
The Excel BITXOR Function
Bitwise Functions
The Excel Bitwise functions convert the supplied integer value(s) to binary form
and then perform an operation on the individual bits.
The result is then converted back to an integer value before being returned.
Further information on Bitwise operations is provided on the
Wikipedia Bitwise Operation Page
Function Description
The Excel BitXor function returns the bitwise 'XOR' (exclusive 'OR') for two supplied integers.
Note: the BitXor function was only introduced in Excel 2013
and so is not available in earlier versions of Excel.
The syntax of the function is:
BITXOR( number1, number2 )
where the supplied number arguments are positive integers.
BitXor Function Examples
Example 1
Formula:
|
A |
B |
1 |
=BITXOR( 5, 6 ) |
(5 and 6 have binary forms 101 and 110) |
2 |
|
|
|
Result:
|
A |
B |
1 |
3 |
(decimal form of 011) |
2 |
|
|
|
In the above example:
Decimal-Binary Conversion
If you want to work through the stages of a bitwise 'XOR' operation you can use the Excel
DEC2BIN and
BIN2DEC functions
to convert between decimal and binary forms.
- The binary form of 5 is 101.
- The binary form of 6 is 110.
- One (and only one) of the binary numbers 101 and 110 has the digit '1' at position 1 (counting from the right).
Therefore, within the result, the rightmost digit is a 1.
- One (and only one) of the binary numbers 101 and 110 has the digit '1' at position 2 (counting from the right).
Therefore, within the result, the digit second from the right is a 1.
- Both of the binary numbers 101 and 110 have the digit '1' at position 3 (counting from the right).
Therefore, within the result, the third digit from the right is a 0.
- The bitwise 'XOR' result is therefore the binary number 011.
- This number is returned in decimal form, as the integer 3.
Example 2
Formula:
|
A |
B |
1 |
=BITXOR( 9, 12 ) |
(9 and 12 have binary forms 1001 and 1100) |
2 |
|
|
|
Result:
|
A |
B |
1 |
5 |
(decimal form of 0101) |
2 |
|
|
|
In the above example:
- The binary form of 9 is 1001.
- The binary form of 12 is 1100.
- One (and only one) of the binary numbers 101 and 110 has the digit '1' at position 1 (counting from the right).
Therefore the rightmost digit of the result is a 1.
- Neither of the binary numbers 101 and 110 have the digit '1' at position 2 (counting from the right).
Therefore, within the result, the digit second from the right is a 0.
- One (and only one) of the binary numbers 101 and 110 have the digit '1' at position 3 (counting from the right).
Therefore, within the result, the third digit from the right is a 1.
- Bothc of the binary numbers 101 and 110 have the digit '1' at position 4 (counting from the right).
Therefore, within the result, the fourth digit from the right is a 0.
- The bitwise 'XOR' result is therefore the binary number 0101.
- This number is returned in decimal form, as the integer 5.
Further information and examples of the Excel BitXor function are provided on the
Microsoft Office website.
BitXor Function Errors
Common Errors
#NUM! |
- |
Occurs if either:
- One or both of the supplied number arguments is a non-integer;
- One or both of the supplied number
arguments is negative or is greater than (2^48)-1.
|
#VALUE! |
- |
One or both of the supplied number arguments is non-numeric.
|