top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

When x>>1 and x/2 gives different result in C/C++?

+3 votes
424 views
When x>>1 and x/2 gives different result in C/C++?
posted Dec 18, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

For positive integers x>>1 and x/2 would be same but for negative its not see the example

x=5
x>>1 is 2
x/2 is also 2

if
x=-5
x/2 is -2
but x>>1 is -3

answer Dec 19, 2015 by Salil Agrawal
0 votes

Answer will be same on positive numbers means(dividing the number by 2).But on negative number it will be not same.

answer Dec 20, 2015 by Rajan Paswan
...