
% Subroutine to transform decimal numbers into other bases.

function BaseConv(Int,Base)

% conversion to new base
i=1;
while Int>0
    % Computing the remainder of the division of Int by Base.
    BaseDig(i)=mod(Int,Base);
    
    % Obtaining the difference between Int and the remainder 
    % and calling this aux. Then, Int variable for the new iteration
    % will be obtained by dividing aux/base.
    aux=Int-BaseDig(i);
    Int=aux/Base;
    i=i+1;
end

% Writing the digits in the right order to express the 
% equivalent new base number.

fprintf('\n New Base=%2.0f\n  ',Base);
fprintf('Rerpresentation in this base=');
for j=i-1:-1:1
    fprintf('%1.0f',BaseDig(j));
end