write a function in matlab that has one input argument and o

write a function in matlab that has one input argument and one output argument. The input will be a vector of 1s and 0s (either 32 or 64). The output is the decimal number you calculate. The function should verify that the vector is valid, and if so, convert it to a decimal number. If not, you need to indicate that to the user. Once you have determined it is a valid vector you need to do the correct conversion (remember to take into account if you are getting a 32 bit or 64 bit values. As explained in the link above there are several different situations that you may run into with your IEEE notation. Your program should be able to calculate both Normalized and Denormalized values. You will also need to indicate positive or negative infinity. As a hint “Inf” is MATLAB’s designation for infinity. Similarly, you can use “NaN” as your output if the input value falls into one of the “Not a Number” situations.

Solution

Matlab code;

%clearing window, variables and figures
clear all;
close all;
clf;
clc;
n=input(\'Whether binary 32 or 64:\');
num=0;
num1=0;
j=1;
if n==32
fprintf(\'\ Enter the %d th bit\',1);
fn=input(\'\ Enter:\');
for i=2:1:32
c=input(\'\ Enter 1 if flotting point has been reached:\');
if c==1
for k=i:1:32
fprintf(\'\ Enter the %d th bit\',k);
num1(j)=input(\'\ Enter:\');
j=j+1;
end
break;
else
fprintf(\'\ Enter the %d th bit\',i);
num(i)=input(\'\ Enter:\');
end
end
sum=0;
n1=length(num1);
for i=1:1:n1
sum=sum+num1(i)*2^-i;
end
n2=length(num);
for i=1:1:n2
sum=sum+num(i)*2^(31-i);
end
if isnumeric(sum)==1
fprintf(\'\ The number denormalized:%d\',sum);
fprintf(\'\ The number normalized:%d\',norm(sum));
if fn==1
fprintf(\'\ The number the number is negative:\');
else
fprintf(\'\ The number the number is positive:\');
end
elseif isinf(sum)==1
if fn==1
fprintf(\'\ Negative infinity\');
else
fprintf(\'\ Positive infinity\');
end
else
fprintf(\'\ Nan\');
end
elseif n==64
fprintf(\'\ Enter the %d th bit\',1);
fn=input(\'\ Enter:\');
for i=2:1:64
c=input(\'\ Enter 1 if flotting point has been reached:\');
if c==1
for k=i:1:32
fprintf(\'\ Enter the %d th bit\',k);
num1(j)=input(\'\ Enter:\');
j=j+1;
end
break;
else
fprintf(\'\ Enter the %d th bit\',i);
num(i)=input(\'\ Enter:\');
end
end
sum=0;
n1=length(num1);
for i=1:1:n1
sum=sum+num1(i)*2^-i;
end
n2=length(num);
for i=1:1:n2
sum=sum+num(i)*2^(63-i);
end
if isnumeric(sum)==1
fprintf(\'\ The number denormalized:%d\',sum);
fprintf(\'\ The number normalized:%d\',norm(sum));
if fn==1
fprintf(\'\ The number the number is negative:\');
else
fprintf(\'\ The number the number is positive:\');
end
elseif isinf(sum)==1
if fn==1
fprintf(\'\ Negative infinity\');
else
fprintf(\'\ Positive infinity\');
end
else
fprintf(\'\ Nan\');
end
else
fprintf(\'\ Invalid input\');
end

result;

Whether binary 32 or 64:32

Enter the 1 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 2 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 3 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 4 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 5 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 6 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 7 th bit
Enter:1

Enter 1 if flotting point has been reached:0

Enter the 8 th bit
Enter:1

Enter 1 if flotting point has been reached:1

Enter the 9 th bit
Enter:1

Enter the 10 th bit
Enter:1

Enter the 11 th bit
Enter:1

Enter the 12 th bit
Enter:1

Enter the 13 th bit
Enter:1

Enter the 14 th bit
Enter:1

Enter the 15 th bit
Enter:1

Enter the 16 th bit
Enter:1

Enter the 17 th bit
Enter:1

Enter the 18 th bit
Enter:1

Enter the 19 th bit
Enter:1

Enter the 20 th bit
Enter:1

Enter the 21 th bit
Enter:1

Enter the 22 th bit
Enter:1

Enter the 23 th bit
Enter:0

Enter the 24 th bit
Enter:0

Enter the 25 th bit
Enter:0

Enter the 26 th bit
Enter:0

Enter the 27 th bit
Enter:0

Enter the 28 th bit
Enter:0

Enter the 29 th bit
Enter:0

Enter the 30 th bit
Enter:0

Enter the 31 th bit
Enter:1

Enter the 32 th bit
Enter:1

The number denormalized:1.065353e+09
The number normalized:1.065353e+09
The number the number is negative:

write a function in matlab that has one input argument and one output argument. The input will be a vector of 1s and 0s (either 32 or 64). The output is the dec
write a function in matlab that has one input argument and one output argument. The input will be a vector of 1s and 0s (either 32 or 64). The output is the dec
write a function in matlab that has one input argument and one output argument. The input will be a vector of 1s and 0s (either 32 or 64). The output is the dec
write a function in matlab that has one input argument and one output argument. The input will be a vector of 1s and 0s (either 32 or 64). The output is the dec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site