Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Has to be in MATLAB code please ! 19. Write a user-defined MATLAB function that

ID: 3349049 • Letter: H

Question



Has to be in MATLAB code please ! 19. Write a user-defined MATLAB function that converts integers written in decimal form to binary form. Name the function b-Bina (d), where the input argument d is the integer to be converted and the output argument b is a vector with Is and Os that represents the number in binary form. The largest number that could be converted with the function should be a binary number with 16 1s. If a larger number is entered as d, the function should display an error message. Use the function to convert the following num- bers: (a) 100 (b) 1,002 (c) 52,601 (d) 200,090

Explanation / Answer

Matlab Script:

function b = Bina(d)
i = 1;
while 1==1
b(i) = rem(d,2);%gives reminder
d = floor(d/2);%takes divisor
if d==0
b = fliplr(b);%actual binary number is flipped version of b
break;
end
i=i+1;
if i>16
error('The given number is large');
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote