function mydec2bin(d)
symbols = '01';
max_len = round (log(d)/log(2)) + 1;
digits = zeros (1, max_len);
for k = max_len:-1:1
digits(:,k) = mod (d, 2);
d = round ((d - digits(:,k))/2);
end
disp(num2str(symbols(digits+1)));
end
for i=1:100
mydec2bin(i)
end
十进制整数转二进制直接用dec2bin就可以了,不知题主遇到什么困难了?