- Categories:
BITSHIFTRIGHT¶
Shifts the bits for a numeric or binary expression n positions to the right.
- Aliases:
BIT_SHIFTRIGHT
- See also:
Syntax¶
Arguments¶
expr1This expression must evaluate to an INTEGER value, a BINARY value, or a value of a data type that can be cast to an INTEGER value.
nThe number of bits to shift by.
Returns¶
Returns an INTEGER value, a BINARY value, or NULL:
When the input expression contains an INTEGER value, returns a signed 128-bit (16-byte) integer, regardless of the size or data type of the input data value.
When the input expression contains a BINARY value, returns a BINARY value.
If any argument is NULL, returns NULL.
Usage notes¶
If the data type of the argument is numeric but not INTEGER (e.g. FLOAT, DECIMAL, etc.), then the argument is cast to an INTEGER value.
If the data type of the argument is a string (e.g. VARCHAR), then the argument is cast to an INTEGER value if possible. For example, the string
12.3is cast to12. If the value cannot be cast to an INTEGER value, then the value is treated as NULL.The function does not implicitly cast arguments to BINARY values.
Examples¶
The following sections contain examples for INTEGER argument values and BINARY argument values.
Using BITSHIFTLEFT and BITSHIFTRIGHT with INTEGER argument values¶
Create a simple table and data:
Run the query:
Using BITSHIFTRIGHT with BINARY argument values¶
Create a simple table and insert the data:
Note
The BINARY values are inserted using the x'value' notation, where value contains
hexadecimal digits. For more information, see Binary input and output.
Run the query: