- 位操作函数
位操作函数
bitand(integer_type a, same_type b)
功能:按位与运算
返回类型: 和输入类型相同
举例:
- mysql> select bitand(255, 32767); /* 0000000011111111 & 0111111111111111 */
- +--------------------+
- | bitand(255, 32767) |
- +--------------------+
- | 255 |
- +--------------------+
- 1 row in set (0.01 sec)
- mysql> select bitand(32767, 1); /* 0111111111111111 & 0000000000000001 */
- +------------------+
- | bitand(32767, 1) |
- +------------------+
- | 1 |
- +------------------+
- 1 row in set (0.01 sec)
- mysql> select bitand(32, 16); /* 00010000 & 00001000 */
- +----------------+
- | bitand(32, 16) |
- +----------------+
- | 0 |
- +----------------+
- 1 row in set (0.01 sec)
- mysql> select bitand(12,5); /* 00001100 & 00000101 */
- +---------------+
- | bitand(12, 5) |
- +---------------+
- | 4 |
- +---------------+
- 1 row in set (0.01 sec)
- mysql> select bitand(-1,15); /* 11111111 & 00001111 */
- +----------------+
- | bitand(-1, 15) |
- +----------------+
- | 15 |
- +----------------+
- 1 row in set (0.01 sec)
bitnot(integer_type a)
功能:按位非运算
返回类型:和输入类型相同
举例:
- mysql> select bitnot(127); /* 01111111 -> 10000000 */
- +-------------+
- | bitnot(127) |
- +-------------+
- | -128 |
- +-------------+
- 1 row in set (0.01 sec)
- mysql> select bitnot(16); /* 00010000 -> 11101111 */
- +------------+
- | bitnot(16) |
- +------------+
- | -17 |
- +------------+
- 1 row in set (0.01 sec)
- mysql> select bitnot(0); /* 00000000 -> 11111111 */
- +-----------+
- | bitnot(0) |
- +-----------+
- | -1 |
- +-----------+
- 1 row in set (0.01 sec)
- mysql> select bitnot(-128); /* 10000000 -> 01111111 */
- +--------------+
- | bitnot(-128) |
- +--------------+
- | 127 |
- +--------------+
- 1 row in set (0.01 sec)
bitor(integer_type a, same_type b)
功能:按位或运算
返回类型:和输入类型相同
举例:
- mysql> select bitor(1,4); /* 00000001 | 00000100 */
- +-------------+
- | bitor(1, 4) |
- +-------------+
- | 5 |
- +-------------+
- 1 row in set (0.01 sec)
- mysql> select bitor(16,48); /* 00001000 | 00011000 */
- +---------------+
- | bitor(16, 48) |
- +---------------+
- | 48 |
- +---------------+
- 1 row in set (0.01 sec)
- mysql> select bitor(0,7); /* 00000000 | 00000111 */
- +-------------+
- | bitor(0, 7) |
- +-------------+
- | 7 |
- +-------------+
- 1 row in set (0.01 sec)
bitxor(integer_type a, same_type b)
功能:按位异或运算
返回类型:和输入类型相同
举例:
- mysql> select bitxor(0,15); /* 00000000 ^ 00001111 */
- +---------------+
- | bitxor(0, 15) |
- +---------------+
- | 15 |
- +---------------+
- 1 row in set (0.01 sec)
- mysql> select bitxor(7,7); /* 00000111 ^ 00000111 */
- +--------------+
- | bitxor(7, 7) |
- +--------------+
- | 0 |
- +--------------+
- 1 row in set (0.01 sec)
- mysql> select bitxor(8,4); /* 00001000 ^ 00000100 */
- +--------------+
- | bitxor(8, 4) |
- +--------------+
- | 12 |
- +--------------+
- 1 row in set (0.01 sec)
- mysql> select bitxor(3,7); /* 00000011 ^ 00000111 */
- +--------------+
- | bitxor(3, 7) |
- +--------------+
- | 4 |
- +--------------+
- 1 row in set (0.01 sec)