3,423
社区成员
发帖
与我相关
我的任务
分享
function f=my_bin2dec(integer,decimal)
% transform a positive binary number to a decimal number
% input:
% integer: integer fraction of a binary number (string)
% decimal: decimal fraction of a binary number (string)
% output:
% f: a decimal number
% eg: f=my_bin2dec('111','001')
int=0;n=length(integer);
for i=1:n
int=int+str2num(integer(i))*2^(n-i);
end
dec=0;m=length(decimal);
for i=1:m
dec=dec+str2num(decimal(i))*2^(-i);
end
f=int+dec;