bit_shift_left

description

syntax

BIT_SHIFT_LEFT(BIGINT x, TINYINT c)

将 BIGINT 类型的 x 向左移动 c 位,并将结果作为 BIGINT 返回。 如果 c 小于 0,则返回零。

example

  1. select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5")
  2. --------------
  3. +------+------+----------------+
  4. | x | c | bit_shift_left |
  5. +------+------+----------------+
  6. | 8 | 0 | 8 |
  7. | 8 | 1 | 16 |
  8. | 8 | 2 | 32 |
  9. | 8 | 3 | 64 |
  10. | 8 | 4 | 128 |
  11. +------+------+----------------+
  12. 5 rows in set (0.04 sec)

对于 BIGINT 类型的最大值 9223372036854775807(即 BIGINT_MAX),进行一位左移的结果将得到 -2。

  1. WITH tbl AS (
  2. SELECT 9223372036854775807 AS BIGINT_MAX
  3. )
  4. SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1)
  5. FROM tbl
  6. --------------
  7. +---------------------+-------------------------------+
  8. | BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) |
  9. +---------------------+-------------------------------+
  10. | 9223372036854775807 | -2 |
  11. +---------------------+-------------------------------+
  12. 1 row in set (0.05 sec)

keywords

  1. BITSHIFT, BITSHIFTLEFT