Home Tutorial Php Sql MySQL Bitwise Operator

 
 

Share on Google+Share on Google+
MySQL Bitwise Operator
Posted on: December 9, 2010 at 12:00 AM
Advertisement
This example illustrates how to find in the binary format of a integer value. 

MySQL Bitwise Operator

This example illustrates how to find in the binary format of a integer value. 

In this example we use the 'bin' keyword to convert in the binary format of a integer value.

Query

create table bitwise(id INT(10) AUTO_INCREMENT, number INT(10), PRIMARY KEY(id));

Query

INSERT INTO bitwise SET number = b'00110101';

Query

INSERT INTO bitwise SET number = 154;

Query

INSERT INTO bitwise SET number = 53;

Query

INSERT INTO bitwise SET number = 148;

Query

INSERT INTO bitwise SET number = 38;

Query

INSERT INTO bitwise SET number = 59;

Query

INSERT INTO bitwise SET number = 106;

Query

select * from bitwise;

Output

+----+--------+
| id | number |
+----+--------+
| 1  | 53     |
| 2  | 154    |
| 3  | 53     |
| 4  | 148    |
| 5  | 38     |
| 6  | 59     |
| 7  | 106    |
+----+--------+

Query

SELECT bin(number) FROM bitwise WHERE number & b'00011000' = b'00011000';

Output

+-------------+
| bin(number) |
+-------------+
| 10011010    |
| 111011      |
+-------------+

Query

SELECT bin(number) FROM bitwise;

Output

+-------------+
| bin(number) |
+-------------+
| 110101      |
| 10011010    |
| 110101      |
| 10010100    |
| 100110      |
| 111011      |
| 1101010     |
+-------------+
Advertisement

Related Tags for MySQL Bitwise Operator:


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