function [s,d]=Decimal2BaseB(u,b)
% DECIMAL2BASEB converts an integer to another base representation
%   [s,d]=Decimal2BaseB(u,b) converts the integer u to base b. d
%   contains the digits as decimal numbers, s is a string containing
%   the digits of the base b represetation e.g. for b=16 (hexadecimal)
%   the digits are 1, 2, ... 9, A, B, C, D, E, F

i=1;
while u~=0
  d(i)=mod(u,b); u=floor(u/b); i=i+1;
end
n=i-1; d=d(n:-1:1); s=[];       % convert to string using char(65)=A
for i=1:n
  if d(i)<10
    s=[s num2str(d(i))];
  else 
    s=[s char(65+d(i)-10)];
  end
end