Why does combining two shifts of a uint8_t produce a different result?
Could someone explain me why: x = x << 1; x = x >> 1; and: x = (x << 1) >> 1; produce different answers in C? x is a *uint8_t* type (unsigned 1-byte long integer). For example when I pass it 128 (10000000) in the first case it returns 0 (as expected most significant bit falls out) but in the second case it returns the original 128 . Why is that? I'd expect these expressions to be equivalent? This is due to integer promotions, both operands of the bit-wise shifts will be promoted to int in both cases. In the second case: x = (x << 1) >> 1; the result of x << 1 will be an int and therefore the