% 读入文件(假定文件名为zd502097043.txt)
cstr = textread('zd502097043.txt','%s');
n = length(cstr);
d = zeros(n,1);
for i=1:n
s = bin2dec( cstr{i}(1) ); % 符号
d(i) = bin2dec( cstr{i}(2:end) ) * (-1)^s;
end
d
% 读入文件(假定文件名为data.txt)
cstr = textread('data.txt','%s');
m = length(cstr{1});
n = length(cstr);
d = zeros(n,1);
for i=1:n
s = bin2dec( cstr{i}(1) ); % 符号
if s==1
d(i)=bin2dec(cstr{i})-2^m;
else
d(i) = bin2dec( cstr{i} ) ;
end
end
此乃正解,上面的答案错的,负数的二进制是补码