Left and right shifting bits

Lets say you had a byte that had bits with values like this:

 
01110011


and you shifted each bit to the right by 1. The result would look like this:

 
00111001


If the compiler shifts all the bits to the right, will the last bit (the bit holding the value of 1) go to the next byte or will it be destroyed? Also did the zero come from the previous byte or was it just added?
Last edited on
the right-most bit is discarded and the left-most bit is set to 0.
Peter87 wrote:
[...] the left-most bit is set to 0.

On unsigned integral types. On signed ones the sign bit is propagated.

Edit: Ups!
n3337 5.8.3 says: "The value of E1 >> E2 is E1 right-shifted E2 bit positions. [...] If E1 has a signed type and a negative value, the resulting value is implementation-defined."
Last edited on
Okay, thanks.
Topic archived. No new replies allowed.