Home Tutorial Php Sql MySQL BIT Type

 
 

MySQL BIT Type
Posted on: December 9, 2010 at 12:00 AM
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(~)

 

Related Tags for MySQL BIT Type:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.