我有这样一个文件,文件是有符号的二进制数据,想使用matlab转换成十进制数据,怎么做?

1111111110111101
1111111111110011
0000000001101101
0000000001000111
1111111110001011
1111111110110111
0000000011000110
0000000010001001
1111111011111111
1111111101000100
0000000101100110
0000000100010101
1111111000101110
1111111010000101
0000001001100011
0000001000001001
1111110011110000
1111110101000011
0000001111101110
0000001110110000
1111101011110111
1111101100000111
0000011010000101
0000011011010111
1111011101011100
1111011000111000
0000110000000111
0000111100111101
1110110101110101
1110001011010111
0010010011110000
0111101001000011
0111101001000011
0010010011110000
1110001011010111
1110110101110101
0000111100111101
0000110000000111
1111011000111000
1111011101011100
0000011011010111
0000011010000101
1111101100000111
1111101011110111
0000001110110000
0000001111101110
1111110101000011
1111110011110000
0000001000001001
0000001001100011
1111111010000101
1111111000101110
0000000100010101
0000000101100110
1111111101000100
1111111011111111
0000000010001001
0000000011000110
1111111110110111
1111111110001011
0000000001000111
0000000001101101
1111111111110011
1111111110111101

% 读入文件(假定文件名为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
此乃正解,上面的答案错的,负数的二进制是补码
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答