Skip to main content

bitand

1. BITAND Function

The BITAND function in H2 database is used to perform a bitwise AND operation on two integers.

2. Syntax

The syntax for the BITAND function in H2 database is as follows:

BITAND(value1, value2)

Arguments

  • value1, value2: The integers on which the bitwise AND operation needs to be performed.

Return

  • The BITAND function returns the result of the bitwise AND operation as an integer.

3. Notes

  • The BITAND function in H2 database performs bitwise AND operation on the binary representation of the input integers.
  • Both value1 and value2 should be integers, and the function will return NULL if any of the arguments is NULL.
  • The BITAND function can be used to extract specific bits or flags from a binary value.

4. Examples

Here are a few examples demonstrating the usage of the BITAND function in H2 database:

Example 1 - Performing a bitwise AND operation on two integers:

SELECT BITAND(5, 3) AS result;

Output:

result
------
1

Example 2 - Using BITAND to extract specific bits:

CREATE TABLE flags (
id INT PRIMARY KEY,
value INT
);

INSERT INTO flags VALUES (1, 7), (2, 10), (3, 5);

SELECT id, value, BITAND(value, 2) AS bit_1,
BITAND(value, 4) AS bit_2
FROM flags;

Output:

id | value | bit_1 | bit_2
---+-------+-------+-------
1 | 7 | 2 | 4
2 | 10 | 2 | 0
3 | 5 | 0 | 4
  • bitor - Bitwise OR operation
  • bitxor - Bitwise XOR operation