Share on Google+Share on Google+

MySQL BIT Type

Ads
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(~)

 

Advertisements

Posted on: December 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Advertisement