|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:21 AM
Points: 5,099,
Visits: 20,191
|
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 1:49 AM
Points: 3,123,
Visits: 4,310
|
|
Good question. These operators are often overlooked and are definately underused.
____________________________________________ Space, the final frontier? not any more... All limits henceforth are self-imposed. “libera tute vulgaris ex”
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:15 AM
Points: 1,476,
Visits: 1,943
|
|
Personally i would rather see them not being used. You dont really gain anything by using them. Only makes the code harder to read. Saving a few keypresses vs loosing readability is in my mind a bad trade.
Well i would think that you wont gain any performance on it anyway. SQL still have to do the math. But havent been able to test... no SQL2008
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 12:55 AM
Points: 1,101,
Visits: 1,191
|
|
+= or *= are quite easy, but |= or even ^= wanted a little thinking on bitwise arithmetics. Nice equestion.
See, understand, learn, try, use efficient © Dr.Plch
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 1:32 AM
Points: 3,187,
Visits: 4,140
|
|
stewartc-708166 (6/20/2010) These operators ... are definately underused. Maybe because they are not compatible with SQL Server 2005 and below?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232,
Visits: 7,022
|
|
Good question, but the explanation is lacking. I think that the +=, -=, etc operators are generally even better known than the bitwise operators used here (even if they were done in SQL-2005 compatible format such as SET @b = @b & 1).
The explanation that should have been there is: & - bitwise AND. Convert operators to binary, do a bit-by-bit AND operation (result bit is 1 if both input bits are 1), then convert the result back to the result data type. In the example here, 5 AND 1 becomes:
5 = 0101 1 = 0001 ---- & 0001 = 1
| - bitwise OR. Convert operators to binary, do a bit-by-bit OR operation (result bit is 1 if either input bit is 1), then convert the result back to the result data type. In the example here, 5 OR 1 becomes:
5 = 0101 1 = 0001 ---- | 0101 = 5
^ - bitwise exclusive OR. Convert operators to binary, do a bit-by-bit exclusive OR operation (result bit is 1 if exactly one bit is 1), then convert the result back to the result data type. In the example here, 5 OR 1 becomes:
5 = 0101 1 = 0001 ---- ^ 0100 = 4
% - modulo. I assume the readers here to be familiar with this operator.
(EDIT - attempt to edit formatting of leading spaces)
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 4:56 AM
Points: 1,256,
Visits: 4,253
|
|
| Picture didn't appear on the e-mail--had to come here before it showed up. That happen to anyone else?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
I had to guess because I didn't know the ^= operator but I knew all the others. I was lucky that the other three were specific enough that I guessed correctly.
So why doesn't the Explanation discuss the ^= operator? What is that?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
| I agree with Hugo - I knew the modulus answer, but had no idea what the others were. So got it correct as only one option had the right value for @e :)
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Today @ 2:51 AM
Points: 21,357,
Visits: 9,531
|
|
Toreador (6/21/2010) I agree with Hugo - I knew the modulus answer, but had no idea what the others were. So got it correct as only one option had the right value for @e :)
Same here, I was instantly 100% sure about the % and low and behold, I didn't have to think any further .
|
|
|
|