bit_shift_right

description

syntax

BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)

Return result of logical right shift of BIGINT type x by c bits.

example

Normal case

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

Logical right shift BIGINT -1 by 1 bits gets BIGINT_MAX

  1. select bit_shift_right(-1, 1)
  2. --------------
  3. +------------------------+
  4. | bit_shift_right(-1, 1) |
  5. +------------------------+
  6. | 9223372036854775807 |
  7. +------------------------+

Return zero if c is less than 0

  1. select bit_shift_right(100, -1)
  2. --------------
  3. +--------------------------+
  4. | bit_shift_right(100, -1) |
  5. +--------------------------+
  6. | 0 |
  7. +--------------------------+
  8. 1 row in set (0.04 sec)

keywords

  1. BITSHIFT, BITSHIFTRIGHT