~uc
is of type int
(value 0xFFFF
). ucInverted
is of type unsigned char
(value 0xFF
), which is then promoted to int
(value 0x00FF
). Thus they are not equal.
I guess you could do if ((unsigned char)~uc == ucInverted)
. Both operands will still undergo promotion, but they will have identical values before the promotion.