venta: (Default)
[personal profile] venta
Is 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 ?

Date: 2008-05-28 03:15 pm (UTC)
From: [identity profile] feanelwa.livejournal.com
White coat syndrome - people don't like to argue with authority figures.

Date: 2008-05-28 03:18 pm (UTC)
From: [identity profile] venta.livejournal.com
I can see how that's related, but I don't think that explains it in my particular case. Someone whom I cheerfully argue with mentioned in passing that a lot of people get that question wrong, and thus I assumed I would too.

Date: 2008-05-28 03:24 pm (UTC)
From: [identity profile] valkyriekaren.livejournal.com
I thought White Coat Syndrome was fear of authority figures causing e.g. false positives on tests (failed memory, high blood pressure). I have it slightly, which is why they always have to take my blood pressure twice because the first result is invariably higher due to anxiety.

Date: 2008-05-28 03:26 pm (UTC)
From: [identity profile] drdoug.livejournal.com
(Techie reply: the smartarse answer to 'express -1 in hex' is to ask whether they mean in two's complement (0xFFFFFFFF), ones' complement (0xFFFFFFFE), pure sign bit (0x80000001), or one of the even more obscure ones I can't remember off the top of my head. Most things are of course two's complement, but ISTR one's complement coming up in some IP-related thing somewhere. Can't think of anything that actually uses a sign bit without a complement but it's the easy-to-understand one.)

Date: 2008-05-28 03:29 pm (UTC)

Date: 2008-05-28 03:31 pm (UTC)
From: [identity profile] venta.livejournal.com
Yes, fair point :) I've never used anything other than two's complement in anger, so feel it'd be a little like checking whether they wanted me to reply to their questions in English or some other language.

Date: 2008-05-28 03:34 pm (UTC)
From: [identity profile] mister-jack.livejournal.com
There's a tendency for people of above average competency to overestimate the skills of others, but I don't think it has a name? That's what:

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.


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.

Date: 2008-05-28 03:34 pm (UTC)
From: [identity profile] feanelwa.livejournal.com
I misinterpreted [livejournal.com profile] venta's post as saying she was asked the question at an interview and almost gave a false positive for not knowing the answer. D'oh!

Date: 2008-05-28 03:36 pm (UTC)
chrisvenus: (Default)
From: [personal profile] chrisvenus
The mathematicians answer on the other hand of course is -1. Its only in computers that this answer is relevant and that's more about how you are storing it. :)

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

Date: 2008-05-28 03:38 pm (UTC)
From: [identity profile] venta.livejournal.com
Sorry, I wasn't very clear about that. This was just someone who has conducted interviews telling me about them.

Date: 2008-05-28 03:39 pm (UTC)
From: [identity profile] venta.livejournal.com
Oh, and the question is technically wrong, -1 in hex is -0x1, since hex is a change of base, not necessarily twos complement.

I agree that's technically true, but I can honestly say I've never seen anyone, in any context, write -0x1 :)

Date: 2008-05-28 03:49 pm (UTC)
chrisvenus: (Default)
From: [personal profile] chrisvenus
And for more options http://en.wikipedia.org/wiki/Ones_complement#Comparison_table is quite interesting. Base -2 being the one that amuses me most... I think they were just lookign for silly answers there though. :)

Date: 2008-05-28 04:10 pm (UTC)
From: [identity profile] beckyc.livejournal.com
FWIW, I've fallen into the trap, even though I know that it's probably not actually going to be that hard. I think there was just a momentary lack of confidence as I tried to decide whether the obvious really was obvious or not.

Date: 2008-05-28 04:10 pm (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com

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

Date: 2008-05-28 04:10 pm (UTC)
From: [identity profile] undyingking.livejournal.com
-1

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

Date: 2008-05-28 04:58 pm (UTC)
From: [identity profile] octalbunny.livejournal.com
Really happy with hair ribbons and a cherry on top.

-0x1 :)

Date: 2008-05-28 05:12 pm (UTC)
From: [identity profile] qatsi.livejournal.com
lack of self-confidence

I once suggested "diffidence" as an opposite for "arrogance", but I think it applies better to your requirement.

Date: 2008-05-28 05:12 pm (UTC)
pm215: (Default)
From: [personal profile] pm215
Can't think of anything that actually uses a sign bit without a complement

IEEE floating point...

Date: 2008-05-28 05:18 pm (UTC)
From: [identity profile] venta.livejournal.com
Can't think of anything that actually uses a sign bit without some sort of weird number-munging :)

Date: 2008-05-28 05:18 pm (UTC)
From: [identity profile] venta.livejournal.com
Base -2, brought to you by the 'because we can' department :)

some IP-related thing somewhere

Date: 2008-05-28 05:21 pm (UTC)
ext_8103: (Default)
From: [identity profile] ewx.livejournal.com
It's used in the checksum algorithm.

Date: 2008-05-28 05:23 pm (UTC)
pm215: (Default)
From: [personal profile] pm215
It's been pointed out that the set of people you see at programming interviews is not a very representative sample of the programming population as a whole. The good programmers will do a few interviews and find a job quickly; or they might find a job by word of mouth or recommendation by a friend. The people who aren't so good will tend to stay in the pool of people looking for a job much longer. So somebody whose idea of the "average programmer" is informed by all the job interviews they've conducted will tend to have a skewed impression of average competence.

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.

Date: 2008-05-28 07:57 pm (UTC)
From: [identity profile] john-the-hat.livejournal.com
I would just like to point out that I am confused. Saying that, I was trained as (and, in my secret heart that I show no-one, am) a civil engineer.

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**
Edited Date: 2008-05-28 07:58 pm (UTC)

Date: 2008-05-29 08:04 am (UTC)
From: [identity profile] bateleur.livejournal.com
The mathematicians answer on the other hand of course is -1

Or perhaps -0x1 for maximum smugness.

Date: 2008-05-29 09:49 am (UTC)
From: [identity profile] dr-mitch.livejournal.com
Put me in the camp that would have immediately just said -1. If they'd wanted to ask how it was stored, that's what they should have asked. But of course I am a mathematician.

Date: 2008-05-29 09:58 am (UTC)
From: [identity profile] venta.livejournal.com
In fairness, because we were only chatting about it, and both knew what we were meaning, the question was never formally expressed. I've no idea how the interviewer would actually have put it.

Date: 2008-05-29 12:32 pm (UTC)
From: [identity profile] dr-mitch.livejournal.com
I think I'm just in an ultrapedantic mood today. I didn't intend to attack the interviewer, which could be how my last comment reads!

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)
From: [identity profile] drdoug.livejournal.com
Oh, yes - UDP checksums, now I remember. And you're allowed to turn them off and send a 0 instead, but if you are doing checksums and it comes out as 0 you have to send 0xFFFF ('minus zero' in ones' comlement) instead so the recipient can tell the difference.

Date: 2008-05-29 01:48 pm (UTC)
From: [identity profile] drdoug.livejournal.com
IAWTP.

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.

Date: 2008-05-29 09:50 pm (UTC)
From: [identity profile] onebyone.livejournal.com
I've heard people claim that an integer is a 32-bit value

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.

Date: 2008-05-30 09:04 am (UTC)
From: (Anonymous)
Nope, I think paranoia sums it up quite nicely! If it helps, remember that paranoia BY DEFINITION is out of touch with reality and can be safely ignored.

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

Date: 2008-05-30 01:22 pm (UTC)
From: [identity profile] venta.livejournal.com
C int's are not necessarily two's complement

*panics*

Really ? Crap. I hadn't realised that.

Date: 2008-05-30 01:22 pm (UTC)
From: [identity profile] venta.livejournal.com
You can disassemble integers for easy storage. I blame Ikea; flatpack fractions are quite nasty.

Date: 2008-05-30 02:18 pm (UTC)
From: [identity profile] onebyone.livejournal.com
Frankly, bitwise operators on integers were probably a mistake in the first place.

Date: 2008-05-30 02:42 pm (UTC)
From: (Anonymous)
Aha!

Profile

venta: (Default)
venta

December 2025

S M T W T F S
 123456
78910111213
14151617181920
212223 24252627
28293031   

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 26th, 2025 10:40 am
Powered by Dreamwidth Studios