Fun with XOR #2

  • Comments posted to this topic are about the item Fun with XOR #2

    Don Simpson



    I'm not sure about Heisenberg.

  • 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

  • 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.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • 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

    select @b-2, @a

    except perhaps as part of deliberate code obfuscation.

    Tom

  • 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



    I'm not sure about Heisenberg.

  • Nice question. Thanks for sharing

  • This was removed by the editor as SPAM

  • Nice question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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.

  • 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).

  • Thanks for the question.



    Everything is awesome!

  • Stewart "Arturius" Campbell (12/8/2014)


    Interesting question, thanks Don

    TomThomson (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

  • 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

  • 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.

  • 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