Hello friends, Applying the right shift operator in c to a number and shifting it right by a single digit is equivalent to dividing that numer by 2.But if the number is negative then it is not equivalent.how come? please give me information about the books in which i can find an explaination. Thanks , Praveen.
On Oct 5, 2001 at 08:41, praveen shinde wrote:
Applying the right shift operator in c to a number and
shifting it right by a single digit is equivalent to dividing that numer by 2.But if the number is negative then it is not equivalent.how come? please give me information about the books in which i can find an explaination.
I'm guessing that when you right shift, the number is padded on the left by 0s. So your number becomes positive. I don't know what you mean by "not equivalent". Is this it? please post some source and output.
You r right when u say that right shift divides the number by 2(by putting a zero). But in case of a negative number, it stores the value in the form of 2's complement. and hence the first bit is 1 (for -ve). So when u right shift, u add a zero (unconditionally) converting the number to positive.
I read this in a Computer Organization and Architecture book by William Stallings and not in a C book.
Goldwyn :o)
Hello friends, Applying the right shift operator in c to a number and shifting it
right by a single digit is equivalent to dividing that numer by 2.But if the number is negative then it is not equivalent.how come?
please give me information about the books in which i can find an
explaination.
Thanks , Praveen.