BITAND

BITAND is an SQL function used to perform a bitwise AND operation on two integer binary values. The result is a new binary value where each bit is a logical AND of the corresponding bits from the input values.

BITAND(n1, n2)

  • n1: This is the first binary number for the BITAND operation. It must be a non-negative integer or a value that can be implicitly converted to an integer.
  • n2: This is the second binary number for the BITAND operation. Similar to n1, it must be a non-negative integer or a value that can implicitly be converted to an integer.

Example

SELECT BITAND(15, 10) as Result FROM dual;

Output

RESULT
------
10

Explanation

The BITAND function performs a bitwise AND operation between the binary representations of the two numbers. In this case, numbers 15 (1111 in binary) and 10 (1010 in binary) are compared. The resulting number is 10 (1010 in binary), because the AND operation results in 1 for each bit where both input bits are 1.

BITAND(bigint, bigint) RETURNS bigint

  • bigint: This is the first parameter of the BITAND function. It represents the first large binary integer on which the bitwise AND operation will be performed.
  • bigint: This is the second parameter of the BITAND function. It represents the second large binary integer on which the bitwise AND operation will be performed.
  • returns bigint: This indicates that the BITAND function will return a result of type large binary integer, which is the result of the bitwise AND operation carried out on the two input parameters.

Example

SELECT BIT_AND(6, 3);

Output

2

Explanation

The BIT_AND() function performs a bitwise AND operation between the bits of the two numbers. In the example, the numbers 6 (binary 110) and 3 (binary 011) were used. The bitwise AND operation results in the number 2 (binary 010).

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.