Re: bit shifting doesn't work as expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Constantin Greubel <constantin.greubel@xxxxxxxxxxxxxxxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux