SelectDB Cloud
SQL 手册
SQL 函数
Bitwise函数
BIT_SHIFT_RIGHT

bit_shift_right

description

syntax

BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)

返回对 BIGINT 类型 x 进行逻辑右移 c 位的结果。

example

Normal case

select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5")
--------------
 
+------+------+-----------------+
| x    | c    | bit_shift_right |
+------+------+-----------------+
| 1024 |    0 |            1024 |
| 1024 |    1 |             512 |
| 1024 |    2 |             256 |
| 1024 |    3 |             128 |
| 1024 |    4 |              64 |
+------+------+-----------------+
5 rows in set (0.03 sec)

BIGINT -1 逻辑右移一位得到的结果是 BIGINT_MAX

select bit_shift_right(-1, 1)
--------------
 
+------------------------+
| bit_shift_right(-1, 1) |
+------------------------+
|    9223372036854775807 |
+------------------------+

如果 c 小于 0 得到的结果始终为 0

select bit_shift_right(100, -1)
--------------
 
+--------------------------+
| bit_shift_right(100, -1) |
+--------------------------+
|                        0 |
+--------------------------+
1 row in set (0.04 sec)

keywords

BITSHIFT, BITSHIFTRIGHT
© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标