My goal here is to remove byte-count+1
bits from the left of this 8-bit integer (or as you'd often call it, unsigned char
.
Should be simple really, but this bit of code
uint8_t val = 0xC3;
uint8_t byte_count = 2;
uint8_t cc = val << (byte_count+1) >> (byte_count+1);
printf("%X", cc);
Gives me C3
as a result.
While this one
uint8_t val = 0xC3;
uint8_t byte_count = 2;
uint8_t cc = val;
cc <<= (byte_count+1);
cc >>= (byte_count+1);
printf("%X", cc);
Gives me just the 3
.
Yes, I've tried putting a bunch of parenthesis around it.
Yes, I've tried casting everything in the expression to uint8_t
.
Why does this happen?