September 17, 2010 at 2:53 am
What is the meaning of Select 2^3? I mean, what is this character "^" in here?? i couldnt get the idea behind that. This is the resultset i got when i ran the query for each 2^0 to 2^9
2^: 1 234567890
-------------------------------------------------------------------------------
Ans: 3 01674510112
Thanks,
Pramod
September 17, 2010 at 3:03 am
It is the SQL Server Bitwise OR operator.
September 17, 2010 at 3:06 am
as mentioned in BOL
Performs a bitwise exclusive OR operation of two integer values. It compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. If both bits are 0 or both bits are 1, the corresponding result bit is set to 0.
Both conditions must be a signed integer data type or both conditions must be an unsigned integer data type.
----------
Ashish
September 17, 2010 at 3:11 am
More correctly, it's the Bitwise Exclusive OR.
The truth tables for OR and XOR (exclusive OR) are different. OR means 'If either of these inputs are true, the output is true'. XOR means 'If one or the other, but not both of the inputs are true, the output is true'
OR truth table:
false OR false = false
true OR false = true
false OR true = true
true OR true = true
XOR truth table:
false XOR false = false
true XOR false = true
false XOR true = true
true XOR true = false
So what the query is doing is converting each input into binary, then doing an XOR on each bit.
2 ^ 3:
00000010 (2)
XOR
00000011 (3)
=
00000001
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 17, 2010 at 3:16 am
Thanks a lot guys. It was very helpful of you all.
Pramod
September 17, 2010 at 3:59 am
Hi Gail
Really good explanation as ever.
Ali
MCTS SQL Server2k8
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply