MySQL BIT Type


 

MySQL BIT Type

This example illustrates how many types of BIT operator are used in the MySQL query and how to used it in the query.

This example illustrates how many types of BIT operator are used in the MySQL query and how to used it in the query.

MySQL BIT Type

This example illustrates how many types of BIT operator are used in the MySQL query and how to used it in the query.

In this example we implement the operator OR( | ), AND( & ), XOR( ^ ), Left Shift(<<), Right Shift(>>) and Invert( ~ ). The query, output and description is as follows:

 

Query

 

Output

 

Description

 

SELECT 39 | 25;

 

+---------+
| 39 | 25 |
+---------+
| 63      |
+---------+

 

Bitwise OR(|)

 

SELECT 39 & 25;

 

+---------+
| 39 & 25 |
+---------+
| 1       |
+---------+

 

Bitwise AND(&)

 

SELECT 1 ^ 1;

 

+-------+
| 1 ^ 1 |
+-------+
| 0     |
+-------+

 

Bitwise XOR(^)
 

 

SELECT 1 ^ 0;

 

+-------+
| 1 ^ 0 |
+-------+
| 1     |
+-------+

 

Bitwise XOR(^)

 

SELECT 11 ^ 3;

 

+--------+
| 11 ^ 3 |
+--------+
| 8      |
+--------+

 

Bitwise XOR(^)

 

SELECT 1 << 2;

 

+--------+
| 1 << 2 |
+--------+
| 4      |
+--------+

 

Shifts a number to the left (<<)

 

SELECT 4 >> 2;

 

+--------+
| 4 >> 2 |
+--------+
| 1      |
+--------+

 

Shifts a number to the right(>>)

 

SELECT 5 & ~1;

 

+--------+
| 5 & ~1 |
+--------+
| 4      |
+--------+

 

Invert all bits(~)

 

Ads