I have the following code:
unsigned char x = 255;
printf(\"%x\\n\", x); // ff
unsigned char tmp = x << 7;
unsign
The shift operator is not defined for the char
types. The value of any char
operand is converted to int
and the result of the expression is converted the char
type.
So, when you put the left and right shift operators in the same expression the calculation will be performed as type int
(without loosing any bit), and the result will be converted to char
.