void test()
{
unsigned char c;
c = (~0)>>1 ;
printf("c is %u\n",c);
}
It prints 255. I was expecting 127 as i was expecting the left most bit to be set to 0 after the right shift. Is this because my compiler is doing Right rotation?
Your compiler is treating ~0 as an int, then shifting, then converting to unsigned char. This program outputs your expected value: