%converts any binary (base-2) number with a finite expansion 
%into an ordinary (base-10) number

str = input('convert this binary number: ','s');  %enter as string
x = str-'0';                                      %convert string to vector

for i=1:length(x)
    if x(i) == -2;          %decimal point stored as value -2
        dec_pt = i;
    end
end

y = zeros(1,length(x)-1);   %binary number with decimal point removed

for i=1:dec_pt-1
    y(i) = x(i);
end
for i=dec_pt+1:length(x)
    y(i-1) = x(i);
end

dec_pt = dec_pt-1;         %move decimal point

num = 0;
for i=1:length(y)
    num = num + y(i)*2^(dec_pt-i);
end

disp('the base-10 number is...')
num
    
