function ShowBin2Dec()
% Iterative and recursive methods for computing the
% base-10 value of a string of bits.

clc
s = '111101001110001101011101';
xI = Bin2DecI(s)
xR = Bin2DecR(s)

function x = Bin2DecI(s)
% s is a string of 0's and 1's and x is its base-10 value
% Iterative method.
t = length(s);
x = 0;
for k =1:t
x = x + 2^(k-1)*str2num(s(t-k+1));
end

function x = Bin2DecR(s)
% s is a string of 0's and 1's and x is its base-10 value
% Recursive method.
t = length(s);
if t==1
x = str2num(s);
else
x = 2*Bin2DecR(s(1:t-1)) + str2num(s(t));
end