function [d N]=todigits(x,b)
% todigits  Find the digits of x.
% Usage:: % [d N]=todigits(x,b). 
%
% Find the N base-b (default 10) digits of x.

% revision history:
% 03/03/04 Mark D. Shattuck <mds>   digits.m
% 02/11/19 mds change name to prevent collision with matlab::digits

%% Main
if(x==0)
  d=0;
  return;
end

if(~exist('b','var'))
  b=10;
  N=ceil(log10(x+.9));
else
  N=ceil(log(x+.9)/log(b)+eps);
end

if(N>=1)
  d=diff(fix(repmat(x,1,N+1)./b.^(N:-1:0)).*b.^(N:-1:0))./b.^(N-1:-1:0);
elseif (N==0)
  d=1;
else
  d=0;
end
