Home Tutorial Php Sql MySQL BIT Type

 
 

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

 

Advertisement

Related Tags for MySQL BIT Type:


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.

Posted on: December 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com