Symantec Interview Question: Division method without using... | Glassdoor

## Interview Question

Associate Software Engineer Interview Herndon, VA

# Division method without using divide operator

2

int divide(int a,int b){
//should return a/b
if (b == 0){ throw new DivisionByZeroException(xxxx);} // or do whatever...
if (b == 1){return a;}
int i = 1;
int temp = b;
while (temp

Jason Peng on Nov 12, 2012
1

i++ should be before temp=b*i, sorry for error

Jason Peng on Nov 12, 2012
2

The other way is to use bitwise operation
(&gt;&gt; or &gt;), you are doing division of 2.
For example,
01000 represents 8
00100 represents 4
00010 represents 2
00001 represents 1
Hopefully you can understand this....
However, you need to take care of when the denominator is odd- which is very difficult to do.
I would recommend my first solution listed above. It is more understandable or less error-prone.

Jason Peng on Nov 12, 2012
0

Use &gt;&gt; to shift both until divisor is 1, the final dividend value is the answer

Anonymous on Nov 6, 2015
0

Someone from Symantec gave me information about what to expect in the job interview at Rooftop Slushie.

https://wwww.rooftopslushie.com

Anonymous on Jul 18, 2019