%% Negative Values
% MATLAB® encodes negative integers using two's complement. For example, to find the two's complement representation of -5, you take the bit pattern of the positive version of the number (00000101), swap each bit (11111010), and then add 1 to the result (11111011).
% Therefore, the bit-wise XOR of -5 (11111011) and 6 (00000110) is -3 (11111101).

a = -5;
bitget(a,8:-1:1,'int8')

%

b = 6;
bitget(b,8:-1:1,'int8')

%

c = bitxor(a,b,'int8')
bitget(c,8:-1:1,'int8')

% Copyright 2012 The MathWorks, Inc.