1.38 Write a user-defined MATLAB function that adds two integers in decimal form. Name the function
c = adddec(a,b), where the input arguments a and b are the numbers to be added in decimal form, and
the output argument c is the result in decimal form. The addition is done in the following way: First, the
numbers a and b are converted to binary form by using the user-defined function intTObina written in
Problem 1.35. Then, the converted two numbers are added using the user-defined function addbin writ-
ten in Problem 1.37. Finally, the result is converted to decimal form by using the user-defined function
binaTOint written in Problem 1.34. The three user-defined functions intTObina, addbin, and
binaTOint can be written as subfunctions inside adddec. The numbers that are being added with the
function cannot be larger than 65,535 each. If a larger number is entered, an error message is displayed.
Use the function in the Command Window to add 60,000 and 12,087.
Solution
If the functions addbin and binaTOint are used as they are in the previous problems, the following
program will still work, but the error messages can be eliminated by replacing the criteria with: