I'm trying to rotate a signed char (*c
), which in binary is 10011010
, right 4 (numRotate
) places. The desired outcome after the shift is 10101001
. The code I currently have is:
void right(char *c, int numRotate) {
*c = (*c >> numRotate) | (*c << (8 - numRotate));
}
According to what I've learnt, this apparently should work to do my desired shift correctly. Instead the outcome I have been getting is 11111001
. I'm not sure what's wrong. Could it be a problem with signed
vs unsigned
char
data types? All the resources I've looked at only use unsigned data types.