BITAND function Oracle

BITAND function used to find a bit is set or not. It returns INTEGER.

Syntax :- BITAND(expr1,expr1)

If the values are the same, the operator returns 1 and return 0 otherwise.
BITAND function first convert both expression into binary format, then compare bit by bit and returns in decimal format

Examples:-

1. BITAND(1,1)  — returns 1
2. BITAND(1,0)  — returns 0
3. BITAND(0,1)  — returns 0
4. BITAND(-1,-1)– returns -1
5.  BITAND(null,null) – returns NULL

6. BITAND(24,18) – returns 8

Explanation:-
Binary representation of 24 is 11000
Binary representation of 15 is 1111

24 15 BITAND Result Explanation
1
1 1 ====> 1 (1 AND 1) is 1
0 1 ====> 0 (0 AND 1) is 0
0 1 ====> 0 (0 AND 1) is 0
0 1 ====> 0 (0 AND 1) is 0

(Note that that bits are considered from right, least significant first)

Result is 1000 in binary format. If you convert 1000 binary into decimal format we get 8.
So BITAND(24,18) = 8

7. BITAND(6,2) – returns 2

Binary representation of 6 is 110
Binary representation of 2 is  10
BITAND returns 10 in Binary, which is 2

8. BITAND(6,3) – returns 2

Binary representation of 6 is 110
Binary representation of 2 is  11
BITAND returns 10 in Binary, which is 2

Advertisements

Author: sqlandplsql

To learn more about the Oracle, SQL, PL SQL, Performance Tuning, Database Modeling, Ubuntu, MySQL etc .Suggestions, comments, feedbacks and referrals are highly appreciated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s