This topic describes the syntax of bitwise functions. This topic also provides examples on how to use the functions.
The following table describes the bitwise functions that are supported by Simple Log Service.
Function | Syntax | Description | Supported in SQL | Supported in SPL |
bit_count(x, bits) | Returns the number of bits 1 in x in binary representation. | √ | √ | |
bitwise_and(x, y) | Returns the result of the bitwise AND operation on x and y in binary representation. | √ | √ | |
bitwise_not(x) | Returns the result of the bitwise NOT operation on x in binary representation. | √ | √ | |
bitwise_or(x, y) | Returns the result of the bitwise OR operation on x and y in binary representation. | √ | √ | |
bitwise_xor(x, y) | Returns the result of the bitwise XOR operation on x and y in binary representation. | √ | √ |
bit_count function
The bit_count function returns the number of bits 1 in x in binary representation.
Syntax
bit_count(x, bits)
Parameters
Parameter | Description |
x | The value of this parameter is of the bigint type. |
bits | This parameter specifies the number of bits, such as 64 bits. |
Return value type
The bigint type.
Examples
Convert the number 24 into a binary number and obtain the number of bits 1 in the binary number.
Query statement
* | SELECT bit_count(24, 64)
Query and analysis results
bitwise_and function
The bitwise_and function returns the result of the bitwise AND operation on x and y in binary representation.
Syntax
bitwise_and(x, y)
Parameters
Parameter | Description |
x | The value of this parameter is of the bigint type. |
y | The value of this parameter is of the bigint type. |
Return value type
The bigint type.
Examples
Perform a bitwise AND operation on 3 and 5 in binary representation.
Query statement
* | SELECT bitwise_and(3, 5)
Query and analysis results
bitwise_not function
The bitwise_not function returns the result of the bitwise NOT operation on x in binary representation.
Syntax
bitwise_not(x)
Parameters
Parameter | Description |
x | The value of this parameter is of the bigint type. |
Return value type
The bigint type.
Examples
Perform a bitwise NOT operation on 4 in binary representation.
Query statement
* | SELECT bitwise_not(4)
Query and analysis results
bitwise_or function
The bitwise_or function returns the result of the bitwise OR operation on x and y in binary representation.
Syntax
bitwise_or(x, y)
Parameters
Parameter | Description |
x | The value of this parameter is of the bigint type. |
y | The value of this parameter is of the bigint type. |
Return value type
The bigint type.
Examples
Perform a bitwise OR operation on 3 and 5 in binary representation.
Query statement
* | SELECT bitwise_or(3, 5)
Query and analysis results
bitwise_xor function
The bitwise_xor function returns the result of the bitwise XOR operation on x and y in binary representation.
Syntax
bitwise_xor(x, y)
Parameters
Parameter | Description |
x | The value of this parameter is of the bigint type. |
y | The value of this parameter is of the bigint type. |
Return value type
The bigint type.
Examples
Perform a bitwise XOR operation on 3 and 5 in binary representation.
Query statement
?1* | SELECT bitwise_xor(3, 5)
Query and analysis results