Home Tutorial Php Sql MySQL BIT

 
 

MySQL BIT
Posted on: December 9, 2010 at 12:00 AM
This example illustrates how to create the table with BIT type field.

MySQL BIT

This example illustrates how to create the table with BIT type field.

In this example we create a table with BIT type field and insert some binary value and then select the table as binary, octal and hexadecimal format. The output is showing in the all three format after converting in the associative format.

 

Query

 

CREATE TABLE t (b BIT(8));

 

Query

 

INSERT INTO t SET b = b'11111111';

 

Query

 

INSERT INTO t SET b = b'1010';

 

Query

 

INSERT INTO t SET b = b'0101';

 

Query
 

 

SELECT b+0, BIN(b+0), OCT(b+0), HEX(b+0) FROM t;
Output

 

+------+----------+----------+----------+
| b+0  | BIN(b+0) | OCT(b+0) | HEX(b+0) |
+------+----------+----------+----------+
| 255  | 11111111 | 377      | FF       |
| 10   | 1010     | 12       | A        |
| 5    | 101      | 5        | 5        |
+------+----------+----------+----------+

 

Related Tags for MySQL BIT:


Ask Questions?

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.