Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


AND & OR


AND & OR

Author
Message
Tom Garth
Tom Garth
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1013 Visits: 1499
I do bitwise operations fairly often, yet was thrown off at first by the & operator. My probelm is I'm also a VB programmer where it is used for string concatenation. My 2nd problem was that I should have read the newsletter earlier in the day.

Nice QOD. The time spent criticizing trick questions would have been put to better use in just reading the question.

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers

davoscollective
davoscollective
SSChasing Mays
SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)SSChasing Mays (609 reputation)

Group: General Forum Members
Points: 609 Visits: 1000
Sorry. I disagree with you about ~10% of people "seeing" the bit datatype and most people cheating.

I do these questions in order to learn. I don't cheat at them because there is no point. I'm not competing against anyone here. I take a stab at it and when I get it wrong I usually end up reading about why and learning something new!

Today I took a stab at 1. Why? Because I don't know anything about how bitwise and/or work. I saw the datatype was bit and I knew straight away that this could only be a zero or a one (and a null as the answer reminded me).

That automatically ruled out all the other answers.
I have now gone and read about what the bitwise operators do .
There are lots of questions like that on here where you have to be careful of datatypes. Its very true in the real world too.

Just because you didn't see the 'bit' and you got it wrong, don't assume that everyone cheats.
Damian Widera-396333
Damian Widera-396333
SSC-Addicted
SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)SSC-Addicted (476 reputation)

Group: General Forum Members
Points: 476 Visits: 321
hodgy (10/14/2009)
arghh!! I spent a few minutes playing with a spreadsheet to mock up the bitwise AND and OR functions (a happy little diversion) and i missed the data type gotcha!

ah well...


That's why I did not play with bytes early in the morning and found the bit trick Smile

Kindest Regards,

Damian Widera
SQL Server MVP,
MCT, MCSE Data Platform, MCSD.NET
Rob Goddard
Rob Goddard
Say Hey Kid
Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)Say Hey Kid (662 reputation)

Group: General Forum Members
Points: 662 Visits: 558
cengland0 (10/14/2009)
I would agree except the question did not say, Why doesn't this produce the expected result of 56? It was not a troubleshooting question but a question about the operators AND and OR.


I don't think the question said anything other than "What is the output of the above"?

I agree that the title could have been changed so that it wasn't misleading but still didn't give the game away. "Bitwise" may have been more appropriate?

All I'm saying is I can see where the question poser is coming from and I quite liked it as it translates well to real world situations, and it's a lesson that is normally learned the hard way. Put it this way, if a dev came to you and asked what was going on, and the variable declarations were nowhere near the code in question, and they'd been mulling this over for a while and specifically asked you to look at their AND/OR operator logic as they were so far up the wrong tree they couldn't see the way back down, how many people would first say, "right, what are the datatypes you're using here?"

- I'm pretty sure I would get suckered into the same staring, head scratching routine and it could take quite a while to get to the bottom of it...

--------
I love deadlines. I like the whooshing sound they make as they fly by. -Douglas Adams
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)

Group: General Forum Members
Points: 9454 Visits: 9517
OOOOHhhhhh!!! Dang! Ya got me! Laugh

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
paul.goldstraw
paul.goldstraw
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1272 Visits: 1765
I'm with Rob, I got this one right (for once!) but often it's these little details that let me down in these questions. Different data type can completely change what is going on. The name of the question is very much like the scenario Rob mentioned too. Sometimes you take a look at a problem with preconceptions, and it can throw you for a while because everything in the logic is screaming at you that it's correct and yet... well I thought it was a good question because it is a lesson not just in bit fields but in taking in all the details and not taking anything for granted.
RBarryYoung
RBarryYoung
SSCrazy Eights
SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)SSCrazy Eights (9.5K reputation)

Group: General Forum Members
Points: 9454 Visits: 9517
IMHO this is a completely fair question. We are after all DBA's and Developers, and these little details matter a lot in our profession. :-)

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Fatal Exception Error
Fatal Exception Error
SSC-Enthusiastic
SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)SSC-Enthusiastic (157 reputation)

Group: General Forum Members
Points: 157 Visits: 386
This is not a trick question but one of fundamentals and/or reading the entire chunk of code. If you knew what a bit was then you would know there was only one logical answer.
Chris Houghton
Chris Houghton
SSChasing Mays
SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)SSChasing Mays (622 reputation)

Group: General Forum Members
Points: 622 Visits: 1664
Personally I can't see the cause for complaint. I didn't understand how the bitwise & and | operators worked so I thought I was toast, then I noticed the datatype and realised there could only be 1 (no pun intended) correct answer. Having got it right I went on to read up on how the & and | operators work. I think this question better suited those with sketchy knowledge of bitwise operations since we had not choice but to look for an alternative method of solving the question straight away. I liked the question, I got it right and it educated me too. Job well done :-D
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10765 Visits: 12019
A good question. Maybe even a very good question.

Maybe the title of the question could be phrased so that it makes it clear that what is being tested is knowledge of how implicit conversion from int to bit works. But that wouldn't be quite as much fun, now would it? and it would have rather given the game away.

Personally I quite like trick questions, since they are like real life - most of the time all those frustrating hours spent wondering how that code could possibly do this are because we've missed some important bit of information that was right under our noses.

I dislike questions where the wrong anser is given as right - but this question was not one of those.

The questions I really hate are those where an answer is given which could be right if the question had mentioned all the constraints that the putter of the question has assumed but not stated, but without those constrains is a dangerous wrong answes that could easily lead to grief if applied in real life. This question was actuallyy just the opposite of that, demonstrating to people that if they assume a constraint (in this case "all variables are typed as int") that is not required by the problem (even worse one which is specifically contradicted by the terms of the problem) they will come to grief. It's a lesson everyone needs to learn. It also demonstrates that looking at all the constraints can give you a shortcut to the solution (and that's another useful lesson), several people commenting that this "this is a bit" constraint led them straight to the right answer.

It seems from the number of unhappy responses that rather a lot of people have learned neither of those lessons.

Tom

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search