MySQL Bitwise Operator


 

MySQL Bitwise Operator

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

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     |
+-------------+

Ads