PLSQL | BITAND Function

The BITAND is an inbuilt function in PLSQL which is used to returns an integer value which is calculated with AND operation of two given input decimal number. Internally these input decimal numbers get converted into binary numbers and then AND operation is performed and results are returned as output.

Syntax:

BITAND(num1, num2)

Parameters Used:
This function is accepting two parameters which are num1 and num2. These two parameters are input decimal number which get converted into binary number internally and on which BITAND function is called.



Return Value:
This function returns an integer value which is calculated with BIT wise AND operation of two given input decimal number.

Supported Versions of Oracle/PLSQL is given below:

  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. Oracle 8i

Let’s see some examples which will illustrate the BITAND function:

Example-1:

DECLARE 
   Test_Number number1 := 5;
   Test_Number number2 := 3;
   
BEGIN 
   dbms_output.put_line(BITAND(Test_Number number1, 
                               Test_Number number2)); 
   
END;  

Output:

1

Here two numbers 5 and 3 are taken as the parameter. These two decimal numbers get converted into the binary equivalent. Binary equivalent of 5 and 3 are 101 and 011 respectively. Later this two binary number goes under AND operation and gives a new binary number 001 whose decimal equivalent is 1 and hence 1 is returned as output.

Example-2:

DECLARE 
   Test_Number number1 := 5;
   Test_Number number2 := 0;
   
BEGIN 
   dbms_output.put_line(BITAND(Test_Number number1, 
                               Test_Number number2)); 
   
END;  

Output:

0

Here two numbers 5 and 0 are taken as the parameter. These two decimal numbers get converted into the binary equivalent. Binary equivalent of 5 and 0 are 101 and 000 respectively. Later this two binary number goes under AND operation and gives a new binary number 000 whose decimal equivalent is 0 and hence 0 is returned as output.

Advantage:
This function is used to calculate BIT wise AND operation for the two given input decimal numbers.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.