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

Write a user-defined MATLAB function that converts integers written in binary fo

ID: 2993702 • Letter: W

Question

Write a user-defined MATLAB function that converts integers written in binary form to decimal form. Name the function d = binaTOint(b), where the input argument b is a vector with 1s and 0s that represents the binary number to be converted and the output argument d is a number in decimal form. The largest number that could be converted with the function should be a binary number with 20 1s. If a larger number is entered for b, the function should display an error message. Use the function to convert the following numbers:


a) 11010


b)  0101100111


c)  11100110001110101


Explanation / Answer

function d=binaTOint(b)

d=0;

if length(b)<=20

for i=1 : length(b)

d=d+ str2num(b(i)) * 2^(lengh(b)-i);

end

d

else

disp('Number size is learger then 20');

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