MySQL BIT_XOR Function

MySQL BIT_XOR is one of the Aggregate Function, which performs Bitwise XOR operation on all bits. First, this MySQL BIT_XOR function converts all decimal values into binary values, and perform bitwise XOR ( X AND (NOT Y)) operation on those binary values.

MySQL BIT_XOR Syntax

The basic syntax of the BIT_XOR Function in MySQL is as shown below:

SELECT BIT_XOR (Expression)
FROM [Source]

The Truth Table behind this MySQL Bitwise XOR function is

xyx BIT_XOR y
000
011
101
110

MySQL BIT_XOR Function Example 1

In this example, we implement the MySQL Bitwise XOR function on different columns in a table. To demonstrate the BIT_XOR, we are going to use the dup employee 2 table data that we shown below

MySQL BIT_OR Function Example 1

The below statement finds the Bitwise XOR values of Sales 1 and Sales 2 columns.

-- MySQL BIT_XOR Function Example
USE company;
SELECT BIT_XOR(Sales1),
       BIT_XOR(Sales2)
FROM dupemploy2;
MySQL BIT_XOR Function Example 2

x = 9 = 1001

y = 12 = 1100

and the MySQL Bitwise XOR for the above bits is 0101 = 0 + 4 + 0 + 1 = 5

BIT_XOR Group By Example

In this example, we are going to use the MySQL Bitwise XOR function along with the Group By clause. For this Bit_XOR Aggregate Function demo, We are going to use the below shown data

MySQL BIT_OR Example 1

BITWISE XOR CODE

-- MySQL Bitwise XOR Function Example
USE company;
SELECT Education,
       BIT_XOR(Yearly_Income)
FROM dupcustomerdetails
GROUP BY Education;
MySQL BIT_XOR Function Example 3