Ernest Friedman-Hill wrote:When you operate on multiple integral values, they're all promoted to the same type -- usually int -- before the operations. So when you try to combine c and c2, you're actually combining (int) c and (int) c2. c2 is sign-extended with a prefix of all ones, not all zeros as you've shown.
If you want to work with just an 8-bit value, then you need to mask off just those bits -- e.g.,
c = (char) (c | (0xff & c2));
Wow...exactly....I had forgotten the 2's complement detail on negative numbers. Wow...it has been like 7 years since the last time I had to deal with bits.
Thanks a million.