MySQL BIT_XOR is one of the Aggregate Function, which performs Bit wise XOR operation on all bits. First, this function will convert all decimal values into binary values, and perform bit wise XOR ( X AND (NOT Y)) operation on those binary values.
In this article we will show you, How to use this BIT_XOR in MySQL with example.
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 function is
|x||y||x BIT_XOR y|
MySQL BIT_XOR Function Example 1
In this example, we will implement the Bitwise XOR function on different columns in a table. To demonstrate the same, we are going to use the dup employee 2 table data that we shown below
The below statement will find the Bit wise 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;
x = 9 = 1001
y = 12 = 1100
and the Bit wise XOR for the above bits is 0101 = 0 + 4 + 0 + 1 = 5
MySQL BIT_XOR Group By Example
In this example, we are going to use the Bit wise XOR function along with the Group By clause. For this, We are going to use the below shown data
-- MySQL Bitwise XOR Function Example USE company; SELECT Education, BIT_XOR(Yearly_Income) FROM dupcustomerdetails GROUP BY Education;
Thank You for Visiting Our Blog