Thanks Damien.
I am clear abt how this example works. But I want to know in general when we have to take 2's complement(is it for only -ve numbers including int)? Because in the earlier example 2's complement is taken for only byte which is -ve.
I tried the same with minor changes like,
1) byte b1=-5;
byte i=0xf;
byte b2=(byte)(b1^i);
I got -12.
ie 1111 1011
0000 1111
------------
1111 0100
I know it is not hard. But I think I am missing something .
Thanks in advance