December 6, 2014 at 12:52 pm
Comments posted to this topic are about the item Fun with XOR #2
Don Simpson
December 6, 2014 at 1:10 pm
The same question (just phrased a little differently) for Monday as we had for Friday seems a bit odd, especially with two points for each one. But it's still a fun question.
It's also still pretty trivial logic, and I find it appalling that 45% (344 out of 771) got it wrong when it was asked on Friday. I hope the number of wrong answers will be lower for the Monday version.
Tom
December 7, 2014 at 9:49 am
DonlSimpson (12/6/2014)
Comments posted to this topic are about the item <A HREF="/questions/T-SQL/119238/">Fun with XOR #2</A>
There are good use cases for bitwise logic in SQL Server. This is not one of them.
Pretty good trivia question, but readers: please do not ever think about using this in production code.
December 7, 2014 at 10:26 am
Hugo Kornelis (12/7/2014)
There are good use cases for bitwise logic in SQL Server. This is not one of them.Pretty good trivia question, but readers: please do not ever think about using this in production code.
Yes, it would indeed be pretty stupid to write
select (@a ^ @b-2) ^ ((@a ^ @b-2) ^ @b-2), (@a ^ @b-2) ^ @b-2
instead of
except perhaps as part of deliberate code obfuscation.
Tom
December 7, 2014 at 10:59 am
Hugo Kornelis (12/7/2014)
There are good use cases for bitwise logic in SQL Server. This is not one of them.Pretty good trivia question, but readers: please do not ever think about using this in production code.
Perhaps you could read the explanation:
Not the easy way to do anything, but might be good for a computer science class.
I think it was pretty clear that this was not a suggested technique.
Don Simpson
December 8, 2014 at 12:15 am
Nice question. Thanks for sharing
December 8, 2014 at 12:43 am
This was removed by the editor as SPAM
December 8, 2014 at 4:45 am
Nice question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
December 8, 2014 at 6:56 am
Actually, I'm wondering if many who got the previous post wrong was because we weren't familiar with the '^' operator. I incorrectly assumed it meant exponentiation.
Granted, not useful in everyday SQL, but the current question is similar to the math behind RAIDed disk. The basic deal is parity is an XOR, P = A^B. If you lose A, then A = P^B = (A^B)^B, and similarly if you lose B.
December 8, 2014 at 7:31 am
dale_berta (12/8/2014)
Actually, I'm wondering if many who got the previous post wrong was because we weren't familiar with the '^' operator. I incorrectly assumed it meant exponentiation.
This might be the case. It has always been one of my biggest gripes about SQL Server. Everywhere else in the known universe (hyperbole to illustrate my level of frustration) ^ means exponent. But SQL Server makes it XOR. I can't tell you how many times that messed me up (okay, probably only 3 or 4, but again, hyperbole for point).
December 8, 2014 at 7:33 am
Thanks for the question.
December 8, 2014 at 8:07 am
Stewart "Arturius" Campbell (12/8/2014)
Interesting question, thanks DonTomThomson (12/6/2014)
The same question (just phrased a little differently) for Monday as we had for Friday seems a bit odd, especially with two points for each one. But it's still a fun question.It's also still pretty trivial logic, and I find it appalling that 45% (344 out of 771) got it wrong when it was asked on Friday. I hope the number of wrong answers will be lower for the Monday version.
Agreed.
+1
December 8, 2014 at 8:07 am
Thanks Don. Fun question.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
December 8, 2014 at 8:44 am
Nice question. I also agree with Tom that 45% is pretty dismal. Knowing the basics is never a bad thing. The more you understand old techniques and how things work under the hood, the better you are at coming up with good and high-performance solutions to current problems.
December 8, 2014 at 9:02 am
I was unhappy with the whole question because I was sure I got the math right. Then I read some of the other comments and realized that ^ means something other than exponent. That is why I still do these each day, sometimes I get exposed to new theories and thoughts, Sometimes it just little things. But, sometimes the little things trip you up and I learned something almost trivial. Trivial until it shows up in someones SQL and you are trying to fix.
Thanks
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply