This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bit shifting doesn't work as expected


Constantin Greubel <constantin.greubel@physik.uni-muenchen.de> writes:

> I hope this is at least the correct address to ask such questions.
> I have the following small programm, and I don't understand why the
> number is feeded with ones from the right, but not with zeros. And the
> next question would be: How can I manage it to get zeros, instead of
> ones?

Your question would be easier to understand if you showed the output
of your program, and also showed the expected output.

However, I suspect that the answer to your question is that doing a
right shift of a variable with a signed type which happens to hold a
negative value is implementation defined.  If you want to reliably and
portably do a right shift of a value with the high bit set, use
'unsigned int' instead of 'int'.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]