Richard Tobin said:
Nonetheless, I think my assumption is likely to be right. Obviously
the best thing to do would be to verify that assumption before
answering the question.
Actually, I'd give the answer I did give, along with weasel words such as
"well, this is the easiest, most obvious way", and then ask whether he had
expected a bit-twiddling answer. If so, I'd be prepared to give it,
obviously.
Just giving the answer you suggested does not seem like a good strategy.
I still think it's a perfectly valid answer. Had I asked the question with
bit-twiddling in mind, and then received that answer, I'd probably laugh
and say "er, oh yeah, good point - well, okay, how about a solution that
doesn't require any function calls?" (And I'd mentally award him a few
points for simplicity and creativity.) I once asked a candidate how he
would rotate an unsigned int. He wrote this:
unsigned int i = 42;
turned the piece of paper around (which I assumed was so that I could see
it), and sat back in an attitude of "okay, I'm ready for the next
question". It took me a moment to work it out, but I gave him 10/10 for
chutzpah and quick thinking. (And yes, then I asked the same question more
precisely, and yes, he came up with a good *technical* answer.)
"You aren't Richard Heathfield by any chance, are you?"
I would assume that the interviewer realised that there were several
errors of varying seriousness, and that he wanted me to list them. Of
course, I might be wrong, but such is life.
Most were obvious, of course, but there was a subtlety in there that I would
expect only an expert to spot. If the candidate saw that one, I would
consider the question to be correctly answered, even if he dismissed the
rest with "oh, and there's a bunch of other stuff wrong as well".