Home » SQL & PL/SQL » SQL & PL/SQL » bitand(x,y)
bitand(x,y) [message #213166] Tue, 09 January 2007 12:57 Go to next message
Matthew Waugh
Messages: 71
Registered: October 2004
Member
Can somebody please explain how this thing works? I'm so lost...

for example...

bitand(144,128) = 128 WHY?

or

bitand(48,32) = 64 WHY?


Thanks!
Re: bitand(x,y) [message #213176 is a reply to message #213166] Tue, 09 January 2007 13:43 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
BITAND function performs bit AND operation. To figure it out, check these examples:
SELECT bitand(5, 3) FROM dual;

101 -> it is binary representation of 5
011 -> it is binary representation of 3
---
001 -> it is the result of the AND operation -> 1

SELECT bitand (15, 7) FROM dual;

1111 -> 15
0111 -> 7
----
0111 -> 7

SELECT bitand(6, 2) FROM dual

0110 -> 6
0010 -> 2
----
0010 -> 2		

SELECT bitand(144, 128) FROM dual;

10010000 -> 144
10000000 -> 128
--------
10000000 -> 128

SELECT bitand(48, 32) FROM dual;   

110000 -> 48
100000 -> 32
------
100000 -> 32 -> NOT 64 as you've said!!!
I hope it was clear enough.
Re: bitand(x,y) [message #213179 is a reply to message #213176] Tue, 09 January 2007 13:54 Go to previous messageGo to next message
Matthew Waugh
Messages: 71
Registered: October 2004
Member
OK...I understand the the binary representations....but I don't see how the AND operation gets you to 001.


101 -> it is binary representation of 5
011 -> it is binary representation of 3
---
001 -> it is the result of the AND operation -> 1


Re: bitand(x,y) [message #213181 is a reply to message #213179] Tue, 09 January 2007 14:04 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Because only 1 AND 1 = 1; anything else (1 AND 0, 0 AND 1, 0 AND 0) = 0. So:
101 -> it is binary representation of 5
011 -> it is binary representation of 3

Vertically:
 1    0    1
AND  AND  AND
 0    1    1
 =    =    =
 0    0    1
Re: bitand(x,y) [message #213186 is a reply to message #213166] Tue, 09 January 2007 14:16 Go to previous messageGo to next message
Matthew Waugh
Messages: 71
Registered: October 2004
Member
OK...then to really round out my ignorance, I don't get why the operations below occur as they do.

1 AND 1 = 1
0 AND 1 = 0
1 AND 0 = 1
Re: bitand(x,y) [message #213188 is a reply to message #213186] Tue, 09 January 2007 14:20 Go to previous messageGo to next message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Why? Because there are only 10 types of people in the world: those who understand binary, and those who don't.

[EDIT] You put it wrong; 1 AND 0 = 0

[Updated on: Tue, 09 January 2007 14:21]

Report message to a moderator

Re: bitand(x,y) [message #213319 is a reply to message #213188] Wed, 10 January 2007 05:25 Go to previous message
gbarbisan
Messages: 67
Registered: August 2006
Location: Treviso - Italy
Member
Littlefoot wrote on Tue, 09 January 2007 21:20
Why? Because there are only 10 types of people in the world: those who understand binary, and those who don't.




Very Happy
Previous Topic: returning a PL/SQL boolean via ODBC from C
Next Topic: Decode statement
Goto Forum:
  


Current Time: Thu Dec 08 18:30:54 CST 2016

Total time taken to generate the page: 0.11043 seconds