With my napsack and a zero for a halo
May. 28th, 2008 03:50 pmIs there a name for the psychological effect whereby you think you don't know the answer to a question just because you've been told it's hard ?
(The cuts here are just provided to explain the concepts behind the question, they can be safely ignored if you know, or don't want to know.)
Recently someone mentioned that they get a lot of programmers in for interview who can't express the integer -1 in hex. Hexadecimal (or hex) is writing numbers in base 16. "Ordinary" numbers are base 10, so for something bigger than 9 you move to two digits. Using hex, you can write 0-9 as normal, then use A-F to express numbers up to 15. The prefix "0x" is often used to show that it's not a decimal number.
So:
9 = 0x9
10 = 0xA
31 = 0x1F
etc.
Expressing negative numbers gets a bit more complicated; to say -10 you don't just use -0xA. Instead you (approximately) imagine that you have a fixed number of digits to store your number in. Let's say we can only have four digits of hex, so the 'biggest' number we can write is 0xFFFF.
If we add 1 to that, we get 0x10000 - but we only have four digits, so we've effectively said that adding one returns us to zero (0x0000). This is basically the same effect you get when your car's mileometer runs out of digits and rolls round to zero again.
So, if we add 1 to 0xFFFF and get 0, 0xFFFF must be equal to -1. Right ? Well, yes. Obviously you need to have a convention to say whether you're doing negative numbers, so you know whether to interpret OxFFFF as a really big number, or as -1.
(Note for techies: two's complement always scares me if I think about it too hard. If anyone can provide a more coherent explanation, please do.)
Now, I think "express -1 in hex" is a very easy question. Thinking of ways in which it might go wrong, I asked how big an integer was. An integer is a whole number: 1, 2, 23472875, etc. A computer will have a set idea of how much memory it uses to store an integer. A bit can store either a 0 or a 1, and 32 bits is fairly normal for an integer. I've heard people claim that an integer is a 32-bit value; it needn't be. If you assume it is, and the computer you're writing code for uses 16-bit or 64-bit integers, Bad Shit will ensue..
32 bits. So that's 0xFFFFFFFF, then. Except, because I knew a lot of people got it wrong, I assumed I was falling into some elephant trap. I wasn't - 0xFFFFFFFF is the correct answer.
Is there a name for that, other than paranoia and lack of self-confidence ?
(The cuts here are just provided to explain the concepts behind the question, they can be safely ignored if you know, or don't want to know.)
Recently someone mentioned that they get a lot of programmers in for interview who can't express the integer -1 in hex. Hexadecimal (or hex) is writing numbers in base 16. "Ordinary" numbers are base 10, so for something bigger than 9 you move to two digits. Using hex, you can write 0-9 as normal, then use A-F to express numbers up to 15. The prefix "0x" is often used to show that it's not a decimal number.
So:
9 = 0x9
10 = 0xA
31 = 0x1F
etc.
Expressing negative numbers gets a bit more complicated; to say -10 you don't just use -0xA. Instead you (approximately) imagine that you have a fixed number of digits to store your number in. Let's say we can only have four digits of hex, so the 'biggest' number we can write is 0xFFFF.
If we add 1 to that, we get 0x10000 - but we only have four digits, so we've effectively said that adding one returns us to zero (0x0000). This is basically the same effect you get when your car's mileometer runs out of digits and rolls round to zero again.
So, if we add 1 to 0xFFFF and get 0, 0xFFFF must be equal to -1. Right ? Well, yes. Obviously you need to have a convention to say whether you're doing negative numbers, so you know whether to interpret OxFFFF as a really big number, or as -1.
(Note for techies: two's complement always scares me if I think about it too hard. If anyone can provide a more coherent explanation, please do.)
Now, I think "express -1 in hex" is a very easy question. Thinking of ways in which it might go wrong, I asked how big an integer was. An integer is a whole number: 1, 2, 23472875, etc. A computer will have a set idea of how much memory it uses to store an integer. A bit can store either a 0 or a 1, and 32 bits is fairly normal for an integer. I've heard people claim that an integer is a 32-bit value; it needn't be. If you assume it is, and the computer you're writing code for uses 16-bit or 64-bit integers, Bad Shit will ensue..
32 bits. So that's 0xFFFFFFFF, then. Except, because I knew a lot of people got it wrong, I assumed I was falling into some elephant trap. I wasn't - 0xFFFFFFFF is the correct answer.
Is there a name for that, other than paranoia and lack of self-confidence ?
no subject
Date: 2008-05-28 03:15 pm (UTC)no subject
Date: 2008-05-28 03:18 pm (UTC)no subject
Date: 2008-05-28 03:24 pm (UTC)no subject
Date: 2008-05-28 03:26 pm (UTC)no subject
Date: 2008-05-28 03:29 pm (UTC)no subject
Date: 2008-05-28 03:31 pm (UTC)no subject
Date: 2008-05-28 03:34 pm (UTC)sounds like to me.
As for twos-complement, I thought the driving force behind it is that it gives you a unique representation for zero, while ones-complement doesn't. I rather like your explanation of it, I've always understood it as defining the highest bit to be -0x8000, which is much less understandable.
Oh, and the question is technically wrong, -1 in hex is -0x1, since hex is a change of base, not necessarily twos complement.
no subject
Date: 2008-05-28 03:34 pm (UTC)no subject
Date: 2008-05-28 03:36 pm (UTC)Of course that would likely also be pedantic since I suspect in context the answer required is obviosuly the computery one (or one of them).
no subject
Date: 2008-05-28 03:38 pm (UTC)no subject
Date: 2008-05-28 03:39 pm (UTC)I agree that's technically true, but I can honestly say I've never seen anyone, in any context, write -0x1 :)
no subject
Date: 2008-05-28 03:49 pm (UTC)no subject
Date: 2008-05-28 04:10 pm (UTC)no subject
Date: 2008-05-28 04:10 pm (UTC)Unique representation is a big advantage over the alternatives, but being able to use the same adder implementation for both signed and unsigned addition is rather convenient too, and at a more abstract level it takes advantage of the mathematically well-understood notion of modular arithmetic.
I'd have said "'-1', but I suspect that's not the answer you're looking for". And not wanted to take the job if they'd not understood the point l-)
no subject
Date: 2008-05-28 04:10 pm (UTC)That's what I was thinking. If it'd been me, I'd have assumed the "trick" of the question would be that you'd blithely assume some particular representation system and babble "0xFFFFFFFF", only for the interviewer to smugly say they'd asked you how it was expressed in hex, not how it was stored in a computer.
Maybe I shouldn't go for any jobs as a programmer...
no subject
Date: 2008-05-28 04:58 pm (UTC)-0x1 :)
no subject
Date: 2008-05-28 05:12 pm (UTC)I once suggested "diffidence" as an opposite for "arrogance", but I think it applies better to your requirement.
no subject
Date: 2008-05-28 05:12 pm (UTC)IEEE floating point...
no subject
Date: 2008-05-28 05:18 pm (UTC)no subject
Date: 2008-05-28 05:18 pm (UTC)some IP-related thing somewhere
Date: 2008-05-28 05:21 pm (UTC)no subject
Date: 2008-05-28 05:23 pm (UTC)Contrariwise, if you're in an environment where the programmers you meet are skewed towards the competent end of the distribution (say, a software company with a decent recruitment procedure) then your impression of the average programmer is going to be rather different, and skewed in the other direction.
no subject
Date: 2008-05-28 07:57 pm (UTC)Hence whereas I understand and follow the reasoning above (not bad for an engineer), there's a little voice in my head saying "Ok, and how is this relevant to 10,000 tons of reinforced concrete....?"
**bounce**
no subject
Date: 2008-05-29 08:04 am (UTC)Or perhaps -0x1 for maximum smugness.
no subject
Date: 2008-05-29 09:49 am (UTC)no subject
Date: 2008-05-29 09:58 am (UTC)no subject
Date: 2008-05-29 12:32 pm (UTC)You're original point still stands of course- the question shouldn't be difficult. And it was probably never intended as a trick question.
Re: some IP-related thing somewhere
Date: 2008-05-29 01:39 pm (UTC)no subject
Date: 2008-05-29 01:48 pm (UTC)Also, when interviewing for programmers, I've been astonished at how many people who look fine on paper turn out to be entirely unable to write code. So we always do a coding test at interview. We'll set them something really pretty simple that a decent programmer could do standing on their head, and give them way more time than they should need. Then we get them to talk us through their solution, and then ask them about alternatives, implementation tradeoffs, testing, that sort of thing.
This works really well: the non-coders stand out a mile, and for the rest it's extremely useful in picking up (a) just how good they are, and (b) how well they work with others, especially when challenged (politely but firmly) about their work.
I find programming tasks harder than the fairly trivial are a lot less useful, since there are so many possible answers, and challenging the candidate's solution properly would take more time than we have.
no subject
Date: 2008-05-29 09:50 pm (UTC)Sun, for example. A Java int is 32-bit regardless of the instruction set(s) of any processor(s) involved.
If you're going to be properly agnostic about the size of an int in C, then you're not allowed to dismiss the two's complement issue, since C int's are not necessarily two's complement. Lest this cause you to panic, all of OpenKODE's signed integer types *are* necessarily two's complement.
no subject
Date: 2008-05-30 09:04 am (UTC)(Though your post reassures me that my decision to pursue a career in art was the correct one. I'm sure my integers used to consist of whole numbers and weren't in bits at all).
no subject
Date: 2008-05-30 01:22 pm (UTC)*panics*
Really ? Crap. I hadn't realised that.
no subject
Date: 2008-05-30 01:22 pm (UTC)no subject
Date: 2008-05-30 02:18 pm (UTC)no subject
Date: 2008-05-30 02:42 pm (UTC)