MySQL BIT


 

MySQL BIT

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

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

 

Ads