简单的问题mysql是否支持位运算

970361 2003-11-26 03:27:51
请问MYSQL的SQL语句是否支持位运算
...全文
230 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangyanan2000 2003-11-26
  • 打赏
  • 举报
回复
MySQL uses BIGINT (64-bit) arithmetic for bit operations, so these operators have a maximum range of 64 bits.

|
Bitwise OR
mysql> SELECT 29 | 15;
-> 31

The result is an unsigned 64-bit integer.
&
Bitwise AND
mysql> SELECT 29 & 15;
-> 13

The result is an unsigned 64-bit integer.
^
Bitwise XOR
mysql> SELECT 1 ^ 1;
-> 0
mysql> SELECT 1 ^ 0;
-> 1
mysql> SELECT 11 ^ 3;
-> 8

The result is an unsigned 64-bit integer.
<<
Shifts a longlong (BIGINT) number to the left:
mysql> SELECT 1 << 2;
-> 4

The result is an unsigned 64-bit integer.
>>
Shifts a longlong (BIGINT) number to the right:
mysql> SELECT 4 >> 2;
-> 1

The result is an unsigned 64-bit integer.
~
Invert all bits:
mysql> SELECT 5 & ~1;
-> 4

The result is an unsigned 64-bit integer.
BIT_COUNT(N)
Returns the number of bits that are set in the argument N:
mysql> SELECT BIT_COUNT(29);
-> 4

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧