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