the bit shift operator in C does not work, as I expect, which is, without a doubt, my misunderstanding, but can someone explain what is happening?
unsigned char in = 155;
unsigned char res;
res = (in << 6) >> 7;
should be the same as
res = in << 6;
res = res >> 7; // can also use res >>= 7;
but this is not so.
First result:
in = 10011011
res = 01001101
Second (as expected):
in = 10011011
res = 00000001
Thus, in the first case, he works with each change of the source data instead of working with the first shift, and then performs the second shift according to the first result. Ideas?
source
share