# BIT 数据类型

__*BIT 数据类型*__

+ 数据类型:
  + `BIT`
+ 比特位值:
  + 列宽 (M):每个值的比特位数
  + 1 到 64 位
+ 示例:
  + 存储 4 位:`status_column BIT (4) `
+ 字面值可表达为
  + `b'1101'`
  + `0b1101`	 
----------------------------------------------------------------
例如:
```
mysql> create table test.tt (id bit(2));
Query OK, 0 rows affected (0.08 sec)

mysql> insert into test.tt values (b'0101010');
ERROR 1406 (22001): Data too long for column 'id' at row 1

mysql> insert into test.tt values (b'010');
Query OK, 1 row affected (0.02 sec)

mysql> select collation(id) from test.tt;
+---------------+
| collation(id) |
+---------------+
| binary |
+---------------+
1 row in set (0.00 sec)

mysql> select hex(id) from test.tt;
+---------+
| hex(id) |
+---------+
| 2 |
+---------+
1 row in set (0.00 sec)
```

- BIT 类型
  - 比特值类型。M 表示比特位的长度,取值范围从1到64,其默认值是1。