• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

C# interview question

5.00 star(s)

Durbs

Contractor Among Contractors
Thanks received
0
Had a tech test today which was in the main ok. One question though did my head in, I was asked something like:

int i = 500;
i = i << 4;

Tell us what i is.

What the hell is the << operator, its probably something dead obvious but I seem to have gone through my career without using << ?
 
Had a tech test today which was in the main ok. One question though did my head in, I was asked something like:

int i = 500;
i = i << 4;

Tell us what i is.

What the hell is the << operator, its probably something dead obvious but I seem to have gone through my career without using << ?

It means the 'the' is definitely over here...

the <<
 
I never used this in real life.

--
int i = 500;

Console.WriteLine("Base2: "+ Convert.ToString(i, 2));

i = i << 4;

Console.WriteLine("Base2: " + Convert.ToString(i, 2));
Console.WriteLine("Decimal: " + i);
--

It outputs:

--
Base2: 111110100
Base2: 1111101000000
Decimal: 8000
--

C# Bitwise Shift Operators
 
Ah, its the left-shift operator, found its name, so

int 500 binary = 111110100

Shift left 4 = 1111101000000 = 8000.

Ah well, got that question wrong then.
 
I never used this in real life.

--
int i = 500;

Console.WriteLine("Base2: "+ Convert.ToString(i, 2));

i = i << 4;

Console.WriteLine("Base2: " + Convert.ToString(i, 2));
Console.WriteLine("Decimal: " + i);
--

It outputs:

--
Base2: 111110100
Base2: 1111101000000
Decimal: 8000
--

C# Bitwise Shift Operators

Ta, I'd just found similar as you posted.

Same here, not used that in anger so dont really feel bad about getting that question wrong.
 
Had a tech test today which was in the main ok. One question though did my head in, I was asked something like:

int i = 500;
i = i << 4;

Tell us what i is.

What the hell is the << operator, its probably something dead obvious but I seem to have gone through my career without using << ?

I had to look it up as well, and I'm an experienced .net developer. I can't think of a practical application for that operand when you have easier access to floating point arithmetic anyway. Even when you're using bitwise operators to encapsulate several Boolean values into a readily-transferable binary number (which is about the only time I get into mucking around with individual bits), the Shift operator doesn't come into play.

Sounds like the sort of meaningless trick question technical interviewers only ever ask when they want to feel clever, or that they think will impress their non-technical boss that is also on the interview panel.
 
Anyone got a real world example where it would be useful?

Dunno, but they are twats for putting that in an interview, fair threw me off my stride it did.

Googling about, it seems more associated with very low level development which as a VB/C#'er I dont touch. Do we have any Level 75 Dark Mages in the house?
 
Sounds like the sort of meaningless trick question technical interviewers only ever ask when they want to feel clever, or that they think will impress their non-technical boss that is also on the interview panel.

Yeah, it was that kind of interview, it kicked off gently with asking me to explain anti-patterns with a smug look. Went ok though (I hope!).
 
Dunno, but they are twats for putting that in an interview, fair threw me off my stride it did.

Googling about, it seems more associated with very low level development which as a VB/C#'er I dont touch. Do we have any Level 75 Dark Mages in the house?

Found this.

I assume you're not writing this sort of stuff, so definitely a knobhead interviewer.
 

Advertisers

Back
Top