function h = dec2bin(d)
%DEC2BIN DEC2BIN(d) returns the binary number corresponding to the decimal
%        number d.  For example, DEC2BIN(202) returns '11001010'.
%
%	

%	Adapted by Marinna Martini from the Mathworks' DEC2HEX by L. Shure

if d==0
   h = setstr('00000000'); return
end
%n = 1 + fix(log(d)/log(16));
n = 1 + fix(log(d)/log(2));
%s = cumprod([1 16*ones(1,n-1)]);
s = cumprod([1 2*ones(1,n-1)]);
g = s;
for i=1:n
        g(i) = fix(d/s(n-i+1));
        d = rem(d, s(n-i+1));
        if g(i) > 9
           h(i) = setstr(g(i) + 'A' - 10);
        else
           h(i) = setstr(g(i) + '0');
        end
end
length(h);
bits=length(h)/8;
if bits ~= fix(bits),
	% not an even multiple of 8, so pad
	npad = 8-((bits-fix(bits))*8);
	h = [num2str(zeros(1,npad)) h];
end
	
	
