% 2-complement (default is on 16 bits)
% x matrix of any dimension

function y=bit2cmp(x, nbits)

    if nargin < 2
        nbits = 16
    end

    cx = bitcmp(x,nbits);
    bg = bitget(x,nbits);
    y = (1-bg) .* x + bg .* (-1-cx);
