I recently noticed a (weird) behavior when I conducted operations using shift >>
<<
!
To explain it, let me write this small run
In the first example:
a
is converted to an int
, shifted left, then right and then converted back to usigned char
. This will result to a=5
obviously.
In the second example:
b
is converted to int
, shifted left, then converted back to unsigned char
.b
is converted to int
, shifted right, then converted back to unsigned char
.The difference is that you lose information in the second example during the conversion to unsigned char