Whats wrong with this code
typedef unsigned char datum; /* Set the data bus width to 8 bits. */
datum pattern;
datum antipattern;
antipattern =
The rules of C require that unsigned char
operands be converted to int
(except in perverse C implementations).
Once the operand is an int
, it is signed, and the ~
operator may give you unexpected results, because the semantics for signed integers and their bit representations are not fully specified by C. The compiler is helpfully warning you about this.
You should use antipattern = ~ (unsigned int) pattern;
. With unsigned int
, you are guaranteed that the value is represented with simple binary.