## Microsoft Interview Question for Software Engineer in Tests

Comment hidden because of low score. Click to expand.
1
of 0 vote

I guess the 1st solution is the best becoz it shifts only one digit left => least prone to overflow...while doing num<<2 shifts the digits 2 bits...which unnecessarily increases the probability of overflow

Comment hidden because of low score. Click to expand.
0
of 0 vote

x >> 1 = x/2
x << 1 = x*2 So,

x/2 + x + 2x = 7x/2 = 3.5x

Comment hidden because of low score. Click to expand.
0
of 0 vote

One more solution:

(num<<3 - num)>>1

This is multiply the number by 7 and divide by 2

Comment hidden because of low score. Click to expand.
0

Why not (num << 2) - (num >> 1)

Comment hidden because of low score. Click to expand.
0
of 0 vote

anyone agree on Nitesh? it seems right..

Comment hidden because of low score. Click to expand.
0
of 0 vote

well the Qs. should be to multiply by 3.5 without using any arithmetic i.e. +,-,/,*
operator.Only then its challenging

Comment hidden because of low score. Click to expand.
0
of 0 vote

x>>1 => x/2 only when x is power of 2.
Example:
if x=3(in decimal)=0011(in binary)
then x>>1 = 0001(in binary) =1(decimal)

do u think 3.5x=3.5*3 is same as (3>>1)+3+(3<<1)

Comment hidden because of low score. Click to expand.
0

Great!

Comment hidden because of low score. Click to expand.
0
of 0 vote

kausik is right. x>>1 only meaning frul when x is power of 2.

Plus!! I believe this question was asked deliberately vague. I don't think this question is to ask multiplying w/o using any arithmetic, but to ask how you would handle integer type to correctly represent x3.5 situation. rounding to the integer is not acceptable..!

Comment hidden because of low score. Click to expand.
-1
of 0 vote

can some one please explain question in detail?
And what "(x>>1)+x+(x<<1)" solution is?

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.