1684

27
+5  Q:

## Interview Question 101 - Binary Number Interpretation

Pretend you're at an interview. The interviewer asks:

What is the decimal value of this binary number?

10110101

What is the first thing you responsed with?

+28  A:

"Is that twos complement?"

@Rowland Shaw, very good answer. I would hire you!
Or one's complement, even. :)
How about reflected binary code aka Gray code?
Curious at the downvote this answer got...
A:

Rightmost bit is least significant, leftmost is most significant.

Unfortunately, that isn't always the case, but I grew up on little endian machines.

EDIT: although if you are trying to point out there are multiple representations, that's a not so great way of asking that. Maybe, how many valid numbers are represented by this bit pattern?

Wow - what machine was that had a endianess of the bits visible?
RTUs and PLCs require knowledge of the endianess to correctly interpret the registers...
Ah - fair enough. Also made me think of serial communications protocols.
A:

I would probably say something like:

"Errmm... the first half is four..."

(Yeah i know it's five, but i would most likely say 4 dunno why)

This should be community wiki though

+17  A:

Thank you for allowing me to be here.
It was an interesting experience.
Goodbye.

That's like asking a contractor, how many inches are in 6 feet?
How many would you like there to be sir?
+1. That kind of inanity indicates to me an organization I want NOTHING to do with.
That kind of "inanity" is extremely important in systems-level programming.
I completely agree with Bob Somers. Samuel, would you hire a contractor who didn't know how many inches are in 6 feet?Both are equally fundamental to their respective trades.
+9  A:

To answer truthfully:

"This is a waste of my time."

I could expound why, but base2/base10 conversion is basic computer math.

When you interview for a position writing for a magazine or newspaper, would you expect to be asked "What is a question mark used for?"

good analogy, +1.
+1  A:

What is the binary value of this decimal number?

10110101

I would respond with 'What is the binary value of this decimal number? 100110100100010010010101'
+4  A:

128 plus 32 plus 16 plus 4 plus 1 equals 181.

Actually, I'd probably start with the other end, too. (1 plus 4 plus 16 plus 32 plus 128 equals 181.)

And what if it's a signed integer?
The question presumes it is a binary number, not computer based representation of an integer. In that context the answer is correct.
+15  A:

What is the first thing you responsed with?

Your expected answer is wrong: “In what endianness?” – this is not the question any sane person who understands our number system would ask. Why? Because regardless of the base, the endianess is always the same by convention. Always.

To elaborate: there is no reason why different rules should apply for binary than, say, for decimal. Endianess of byte representations only plays a role when used in a context where it obviously matters, because it emulates a particular system or because it encodes information that is written from left to right and should follow this direction (useful when explaining the Bitap algorithm for string search.

Similarly, the question of sign does not occur. A negative number is written with a minus in front of it! Again, the only exception is when dealing with encodings that emulate a specific hardware that is not capable of expressing a sign and needs to encode this in the most significant bit (say).

However, I would propose that this question would likely be asked by a company that writes protocols for communication with hardware devices. I used to write software for communication with RTUs and PLCs and if you didn't know that endianness and sign encoding was important in this situation...
...you wouldn't be the person they hired.
balabaster: This is an obvious context then. And for such cases, I explicitly gave the example of the Bitap algorithm. The OP intentionally left out all context to prove his damaged ego because one of his answers to another question was downvoted by quite a lot of people.
Regarding the answer: that's probably the way a mathematician or non-computer scientist would think, since in pure math there's no endianness or twos complement notation, etc. It might be valid to say that's not the kind of person you'd want for low-level programming.
David: by the way, I'm currently working with low-level code in a library, bit frobbing is my daily bread. Still, I'm aware that mine is a highly specialized field and generalization seems unreasonable.
@Konrad - I did say "However"... it was rather as a food for thought comment, not a "you're wrong" comment.
@balabaster - He asked a question, here, about a single-byte value. I don't see where endianness comes into play.
@Eddie - there's a whole array of hardware out there that only stores 4 bits in a register. Consequently this is a relevant comment.
The question says "[...] of this binary _number_" not "[...] of this bit-vector" or "[...] of this binary representation of a number" - and that is well-defined as a mathematical entity...
+34  A:

"Sir, I am fluent in six million forms of communication. This signal is not used by the Alliance. It could be an Imperial code."

Seriously though, I see little need to translate binary to decimal in most programming positions

Glad to see someone else appreciated it :) I think this ought to be community wiki'ed though
No idea why this was downvoted, if I were the interviewer, i would remark "Quick-Witted and definitely geeky, so as a person he seems to fit into the team"
Haha - hilarious.
+1. I would hire you.
real geeks do give real answers to questions like this.
It's hilarious that the top answer to this question is a Star Wars quote... sadly I've already given it +1, so I can't give it any more. Can someone else +1 it for me?
+1 01101000011000010110100001100001011010000110000101101000011000010110100001100001 = hahahahaha
+9  A:

Do you have a calculator?

I don't understand why -1 if they don't like an answer to a subjective question. This is perfectly acceptable. I would rather hire a dev smart enough to save time and use a calculator than one that would attempt to calculate the value on paper or in their head.
Some people like to downvote just for downvoting...
+2  A:

"see you!"

Why -1? It's an answer to a question.
People are dumb. +1
+1  A:

id say 181 because I'm guessing he talking about subnets.

but I have a Cisco background so...

+1  A:

The decimal value of that binary number is 181, or possibly -74 if it is a signed byte. Are you suggesting that other values are possible?

A:

The first thing I'd ask for is a piece of paper. The second thing I'd ask for is a better question.

+7  A:

If it was for a simple scripting job, I'd likely give the simple answer 181. If it was for something more technical that was likely to involve me needing to understand storage of floating point data - for instance communication with hardware devices or teaching computational theory, I'd probably ask a slew of questions similar to:

1. How big are the data registers and is this data big endian or little endian?
2. Is this a signed or unsigned decimal?
3. When you say "decimal" are we talking .NET decimal which is holds no floating point or are we talking math decimal which does?
4. Are there any bits reserved for a mantissa? If so, how many?
5. Is this written as LSB or MSB?

This would likely be responded to by the interviewer with the following questions:

1. What is endian?
2. What is different about .NET decimals than regular decimals?
3. What is a mantissa?
4. What is LSB and MSB?

Or better still, their eyes would glaze over when they failed to understand what I was talking about. At which point I'd give them my original answer of 181 having firmly made the point that if an interviewer doesn't understand the depth of a question they shouldn't be asking it in the first place...

Edit 1: Alternatively I'd be feeling extra cocky and respond with something like

"I can see why you would expect me to say 181, but you'd be wrong."

and then leave them wondering what I meant by that...

Edit 2: Of course, I'd rather have an exam paper with a bunch of these unanswerable questions that most "developers" fail because at least it indicates that the company is trying to hire good developers instead of hiring just anyone off the street - even if they suck at picking good interview questions.

Have you encountered hardware where the endianness of the *bits* is relevant?
Yep - I used to write software to communicate with RTUs and PLCs(amongst others) and communication with these devices requires knowledge of the format of the registers, including endianess, signs, mantissas etc. I believe this is also true of any device using Texas Instruments chips.
I'm thankful to say I haven't had to do that in the last 6 months though, I write regular software now where the framework can handle it all for me.
I guess I should clarify - in a few cases, the registers only hold 4 bits instead of 8 as you to which you are alluding.
I've never encountered machine registers where bits had an endianness, I have to say. I've done a lot of embedded programming, but none on RTUs and PLCs. Mostly on custom embedded hardware. I've certainly encountered many 32-bit and 16 bit registers where you care about endianness.
Some of the TI components have 4 bit registers, so any device that is built on these would likewise require such handling
+5  A:

I'd probably wonder why he asked, but the binary number 10110101 equals the decimal number 181 (or the hexadecimal B5 or the octal 265). How binary numbers are used by computer systems does not matter, the question itself is purely about the number.

+2  A:

"Sure, do you have pen and paper?"

+6  A:

"How much RAM you guys got on the machines here, 640KB?"

A:

FIRST thing to respond with: 2009 AD

+1  A:

It depends on what your definition of "is" is.

+1  A:

0xB5. Decimal is for marketing cronies.

Hahaha, +1 for the laugh.
+1  A:

If you honestly wanted to get the right answer, you'd need to know the encoding of the bits. Bits are just bits until you decide on their meaning.

The encoding is an equation that tells you the value given the digits.. You could assume it's `d[0]*2^7+d[1]*2^6+d[2]*2^5+...` (regular unsigned 8 bit int)

Similarly, the digits 1 8 1 may represent apples/oranges/pears with different values each, or the number 181, or the number 1.81, or -81, or +81, or just about anything you could possibly care to think about.

I probably would have answered 181, and just argued with the guy if he seemed to think I was wrong, since his answer can't be right any more than mine can.

+3  A:

Asking about the endianness, or anything, is like saying 7+7=41. Binary is base 2. 10110101 in base 2 is 181. Always. If it was a negative number, it would have a minus sign, if it was fractional, it would have a dot.

A:

There are no standard 8 bit decimal (floating point) formats...

A:

I ask a similar question on my interview "quiz"

Why? Because 75% of the so called "experienced coders" get it wrong.

I also throw in a few Hex/decimal conversions. These are just the first few warm-up questions.

In the OP's question, I would accept any endian, signed, or unsigned as an OK answer.

Then I show code snippets and ask them to add/modify the code to solve a problem, some problems are obviously solved with recursion, others operator overloading. Basically probing the OOP ability of the candidate. I even tell them that they dont really have to get the questions right, they just need to demonstrate they know the concepts. Surprisingly, the vast majority of people who look great on a resume, fail miserably with simple OOP concepts.

+1  A:

I would say: there are 10 types of people, those who understand binary and those who cannot. I'm of the second type.

"I'm of the tenth type."
A:

if it is converted to base10, then wouldn't the answer be simply 181 ?