1. binary for -5 is 11111011 (8 bits only since it's a byte)
2. binary for 0xff is 00000000 00000000 00000000 11111111 (ints have 32 bits)
3. the byte is promoted to int, giving you 32 bits
00000000 00000000 00000000 11111011 // -5 promoted to int
4. ^ (xor) operator applied
00000000 00000000 00000000 11111011
00000000 00000000 00000000 11111111
------------------------------------
00000000 00000000 00000000 00000100
Based on the following truth table:
op1 | op2 | (op1 ^ op2) |
--- | --- | ----------- |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
5. result of step 4 is cast to byte, leaving only the 8 rightmost bits: 00000100 (4 decimal)
6. println() outputs numeric values in decimal.
J.Lacar
(tried to eliminate space before the truth table but couldn't)
[This message has been edited by JUNILU LACAR (edited March 10, 2001).]