function out=TwosComp(hexstr,bits)

  if nargin<2 
    bits=length(hexstr)*4;
  end
  fullrange=2^bits;

  out=mod(hex2dec(hexstr)+fullrange/2,fullrange)/fullrange;