Bitwise functions v15

The bitwise functions include BITAND and BITOR.

BITAND

The BITAND function performs a bitwise AND operation and returns a value based on the data type of input argument. The signature is:

BITAND(<expr1>, <expr2>)

The input data type of expr1 and expr2 is a NUMBER on which the bitwise AND operation is performed. The BITAND compares each bit of expr1 value to the corresponding bit of exp2 using a bitwise AND operation. It returns the value based on the data type of the input argument. If either argument to BITAND is NULL, the result is a NULL value.

Return types

The BITAND function returns the same value as the data type of the input argument.

Examples

This example performs an AND operation on the numbers 10 and 11.

edb=# SELECT BITAND(10,11) FROM DUAL;
Output
bitand 
--------
     10
(1 row)

BITOR

The BITOR function performs a bitwise OR operation and returns a value based on the data type of the input argument. The signature is:

BITOR(<expr1>, <expr2>)

The BITOR compares each bit of expr1 value to the corresponding bit of exp2 using a bitwise OR operation. It returns the value based on the data type of the input argument.

Return types

The BITOR function returns the same value as the data type of the input argument. If all the values of a column are NULL, the BITOR returns NULL.

Examples

This example performs an OR operation on the numbers 10 and 11.

edb=# SELECT BITOR(10,11) FROM DUAL;
Output
bitor 
-------
    11
(1 row)

BITWISE OPERATORS

The bitwise operators perform the same operation as BITAND and BITOR. The bitwise operators are:

  • &: (Bitwise AND) Return the result of a bitwise AND operation performed on the input type.

  • |: (Bitwise OR) Return the result of a bitwise OR operation performed on the input type.

Examples

This example uses the & operator and returns the output as BITAND of the input:

edb=# SELECT 10&11 FROM DUAL;
Output
?column? 
----------
       10
(1 row)

This example uses the | operator and returns the output as BITOR of the input:

edb=# SELECT 10|11 FROM DUAL;
Output
?column? 
----------
       11
(1 row)