T
toe
I have a byte called "x". I want byte "y" to be the complement of
"x" (i.e. all the bits flipped).
Initially I wrote:
char unsigned x, y;
...
x = 72;
y = ~x;
But then I thought that the following might happen on your average
system (CHAR_BIT == 8, sizeof(int) == 4):
1) x is promoted to signed int.
2) The complement is take of this signed int.
3) This signed int is then converted to an unsigned char
Am I right in thinking that this is what will happen? If so, would I
be wise to do the following instead:
y = ~(unsigned)x;
"x" (i.e. all the bits flipped).
Initially I wrote:
char unsigned x, y;
...
x = 72;
y = ~x;
But then I thought that the following might happen on your average
system (CHAR_BIT == 8, sizeof(int) == 4):
1) x is promoted to signed int.
2) The complement is take of this signed int.
3) This signed int is then converted to an unsigned char
Am I right in thinking that this is what will happen? If so, would I
be wise to do the following instead:
y = ~(unsigned)x;