G
Grant
Are the bitwise operators >>, <<, &, |, ~, ^ only defined for
non-negative values?
The little program below produces the output
3 255
I expected to get the 3 but why does it produce the 255 when the
variable c is not typecast first?
#include <stdio.h>
int main(int argc, char **argv) {
char c = -1;
unsigned char uc1 = (unsigned char)c >> 6;
unsigned char uc2 = c >> 6;
printf("%hhu %hhu\n", uc1, uc2);
return 0;
}
non-negative values?
The little program below produces the output
3 255
I expected to get the 3 but why does it produce the 255 when the
variable c is not typecast first?
#include <stdio.h>
int main(int argc, char **argv) {
char c = -1;
unsigned char uc1 = (unsigned char)c >> 6;
unsigned char uc2 = c >> 6;
printf("%hhu %hhu\n", uc1, uc2);
return 0;
}