• 位操作函数

    位操作函数

    bitand(integer_type a, same_type b)

    功能:按位与运算

    返回类型: 和输入类型相同

    举例:

    1. mysql> select bitand(255, 32767); /* 0000000011111111 & 0111111111111111 */
    2. +--------------------+
    3. | bitand(255, 32767) |
    4. +--------------------+
    5. | 255 |
    6. +--------------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitand(32767, 1); /* 0111111111111111 & 0000000000000001 */
    2. +------------------+
    3. | bitand(32767, 1) |
    4. +------------------+
    5. | 1 |
    6. +------------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitand(32, 16); /* 00010000 & 00001000 */
    2. +----------------+
    3. | bitand(32, 16) |
    4. +----------------+
    5. | 0 |
    6. +----------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitand(12,5); /* 00001100 & 00000101 */
    2. +---------------+
    3. | bitand(12, 5) |
    4. +---------------+
    5. | 4 |
    6. +---------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitand(-1,15); /* 11111111 & 00001111 */
    2. +----------------+
    3. | bitand(-1, 15) |
    4. +----------------+
    5. | 15 |
    6. +----------------+
    7. 1 row in set (0.01 sec)

    bitnot(integer_type a)

    功能:按位非运算

    返回类型:和输入类型相同

    举例:

    1. mysql> select bitnot(127); /* 01111111 -> 10000000 */
    2. +-------------+
    3. | bitnot(127) |
    4. +-------------+
    5. | -128 |
    6. +-------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitnot(16); /* 00010000 -> 11101111 */
    2. +------------+
    3. | bitnot(16) |
    4. +------------+
    5. | -17 |
    6. +------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitnot(0); /* 00000000 -> 11111111 */
    2. +-----------+
    3. | bitnot(0) |
    4. +-----------+
    5. | -1 |
    6. +-----------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitnot(-128); /* 10000000 -> 01111111 */
    2. +--------------+
    3. | bitnot(-128) |
    4. +--------------+
    5. | 127 |
    6. +--------------+
    7. 1 row in set (0.01 sec)

    bitor(integer_type a, same_type b)

    功能:按位或运算

    返回类型:和输入类型相同

    举例:

    1. mysql> select bitor(1,4); /* 00000001 | 00000100 */
    2. +-------------+
    3. | bitor(1, 4) |
    4. +-------------+
    5. | 5 |
    6. +-------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitor(16,48); /* 00001000 | 00011000 */
    2. +---------------+
    3. | bitor(16, 48) |
    4. +---------------+
    5. | 48 |
    6. +---------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitor(0,7); /* 00000000 | 00000111 */
    2. +-------------+
    3. | bitor(0, 7) |
    4. +-------------+
    5. | 7 |
    6. +-------------+
    7. 1 row in set (0.01 sec)

    bitxor(integer_type a, same_type b)

    功能:按位异或运算

    返回类型:和输入类型相同

    举例:

    1. mysql> select bitxor(0,15); /* 00000000 ^ 00001111 */
    2. +---------------+
    3. | bitxor(0, 15) |
    4. +---------------+
    5. | 15 |
    6. +---------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitxor(7,7); /* 00000111 ^ 00000111 */
    2. +--------------+
    3. | bitxor(7, 7) |
    4. +--------------+
    5. | 0 |
    6. +--------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitxor(8,4); /* 00001000 ^ 00000100 */
    2. +--------------+
    3. | bitxor(8, 4) |
    4. +--------------+
    5. | 12 |
    6. +--------------+
    7. 1 row in set (0.01 sec)
    1. mysql> select bitxor(3,7); /* 00000011 ^ 00000111 */
    2. +--------------+
    3. | bitxor(3, 7) |
    4. +--------------+
    5. | 4 |
    6. +--------------+
    7. 1 row in set (0.01 sec)