Please do this in Matlab make sure to provide proper comment

Please do this in Matlab (make sure to provide proper commenting).

Write a function that adds two binary numbers that are entered by the user. You may represent each binary number as a string of 0\'s and 1\'s. Remember that the calculations need to start at the end of the strings. For binary numbers of different length, you may pad the shorter number with 0\'s in the front. Also, make sure that the carry bit is implemented properly. For example, the solution of 1 + 1 = 10.

Solution

prompt=\'enter 1 binary number\';
x = input(prompt);
str1 = int2str(x); %convert to string
prompt=\'enter 2 binary number\';
y = input(prompt);
str2 = int2str(y);


ans1=dec2bin(bin2dec(str1)+bin2dec(str2));%adding in decimal and then convert the decimal result in binary

Please do this in Matlab (make sure to provide proper commenting). Write a function that adds two binary numbers that are entered by the user. You may represent

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site