Different operators are not declared for byte - both operands get before int , and the result is int . For example, adding:
byte byte1 = 0x00; byte byte2 = 0x00; byte byte3 = byte1 + byte2;
Note that compound assignments work:
byte1 += byte2;
There was a recent SO question in this question. I agree that this is especially unpleasant for bitwise operations, although where the result should always be the same size, and this is a logically completely valid operation.
As a workaround, you can simply return the result in bytes:
byte byte3 = (byte) (byte1 & byte2);
Jon skeet
source share