Bitwise functions perform bit-level AND, OR, XOR, NOT, and count operations on bigint values.
Log Service supports the following bitwise functions.
|
Function name |
Syntax |
Description |
SQL support |
SPL support |
|
bit_count(x, bits) |
Calculates the number of set bits (1s) in x. |
√ |
√ |
|
|
bitwise_and(x, y) |
Performs a bitwise AND operation on x and y. |
√ |
√ |
|
|
bitwise_not(x) |
Performs a bitwise NOT operation on x. |
√ |
√ |
|
|
bitwise_or(x, y) |
Performs a bitwise OR operation on x and y. |
√ |
√ |
|
|
bitwise_xor(x, y) |
Performs a bitwise XOR operation on x and y. |
√ |
√ |
bit_count
Calculates the number of set bits (1s) in x.
Syntax
bit_count(x, bits)
Parameters
|
Parameter |
Description |
|
x |
A bigint value. |
|
bits |
The number of bits. For example, 64. |
Return value type
bigint type.
Examples
Calculate the number of set bits in the binary representation of 24:
-
Query statement
* | SELECT bit_count(24, 64) -
The query returns
2.
bitwise_and
Performs a bitwise AND operation on x and y.
Syntax
bitwise_and(x, y)
Parameters
|
Parameter |
Description |
|
x |
A bigint value. |
|
y |
A bigint value. |
Return value type
bigint type.
Examples
Perform a bitwise AND operation on 3 and 5:
-
Query statement
* | SELECT bitwise_and(3, 5) -
The query returns
1in the_col0column.
bitwise_not
Performs a bitwise NOT operation on x.
Syntax
bitwise_not(x)
Parameters
|
Parameter |
Description |
|
x |
A bigint value. |
Return value type
bigint type.
Examples
Perform a bitwise NOT operation on 4:
-
Query statement
* | SELECT bitwise_not(4) -
The query returns
-5in the_col0column.
bitwise_or
Performs a bitwise OR operation on x and y.
Syntax
bitwise_or(x, y)
Parameters
|
Parameter |
Description |
|
x |
A bigint value. |
|
y |
A bigint value. |
Return value type
bigint type.
Examples
Perform a bitwise OR operation on 3 and 5:
-
Query statement
* | SELECT bitwise_or(3, 5) -
The query returns
7.
bitwise_xor
Performs a bitwise XOR operation on x and y.
Syntax
bitwise_xor(x, y)
Parameters
|
Parameter |
Description |
|
x |
A bigint value. |
|
y |
A bigint value. |
Return value type
bigint type.
Examples
Perform a bitwise XOR operation on 3 and 5:
-
Query statement
* | SELECT bitwise_xor(3, 5) -
The query returns
6.