Answer:
function [result] = potd11(userInput)
result = [0];
d = 0;
while d < userInput
result = [result, randi([0,1])];
d = sum(result .* (2.* ones(1, numel(result))).^(numel(result)-1 :-1:0));
end
end
Step-by-step explanation:
- Initialize the variables from 0 as a starting point.
- Use a while to run it until d is less than userInput variable.
- Add random 1's and 0's to the array.
- Return the binary result when it's decimal equivalent is larger than the input number.