Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

AND & OR Expand / Collapse
Author
Message
Posted Wednesday, October 14, 2009 4:41 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
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
Post #803174
Posted Wednesday, October 14, 2009 7:06 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 6:32 AM
Points: 472, Visits: 878
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.
Post #803200
Posted Thursday, October 15, 2009 1:58 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 5:10 PM
Points: 458, Visits: 272
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 :)


Kindest Regards,

Damian Widera
SQL Server MVP,
MCT, MCSE Data Platform, MCSD.NET
Post #803273
Posted Thursday, October 15, 2009 7:13 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, May 24, 2013 5:20 AM
Points: 660, 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
Post #803412
Posted Thursday, October 15, 2009 7:10 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294, Visits: 9,483
OOOOHhhhhh!!! Dang! Ya got me!

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #803904
Posted Friday, October 16, 2009 8:45 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:14 AM
Points: 1,101, Visits: 1,453
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.
Post #804254
Posted Friday, October 16, 2009 5:46 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294, Visits: 9,483
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."
Post #804622
Posted Monday, October 19, 2009 7:35 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, June 3, 2014 7:31 AM
Points: 155, 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.
Post #805021
Posted Friday, October 23, 2009 7:43 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 2:46 AM
Points: 558, Visits: 1,487
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
Post #807885
Posted Wednesday, November 4, 2009 9:16 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:27 AM
Points: 7,792, Visits: 9,546
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
Post #813666
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse