Write a MATLAB function the performs the operation of a half-adder, call it half
ID: 1810926 • Letter: W
Question
Write a MATLAB function the performs the operation of a half-adder, call it half_add. The function should have two inputs, a and b, and return two outputs, X and c. Then, write another function, call it full_add, that invokes half_add to perform the operation of a full adder. The function full_add should have three inputs, a, b and c_in, and return two outputs, s and c_out. Finally, write a program that uses the function full_add to find and display s and c_out for each possible combination of a, b, and c_in.
Explanation / Answer
function[a,b] = half_adder[ a,b]
x = Xor(a,b);
c = a&b;
Function[ S,Cout] = Full_adder[ a,b,cin]
[X,C] = half_adder[a,b];
Sum =Xor( Cin, Xor(X,C));
Cout = X&C | C&Cin | C&Cin;
a =1 , b =1 , Cin =1
[S,C] =Full_adder[ 1,1,1]
a =0 , b =0 , Cin =1
[S,C] =Full_adder[ 0,0,1]
a =1 , b =1 , Cin =0
[S,C] =Full_adder[ 1,1,0]
a =1, b =0 , Cin =1
[S,C] =Full_adder[ 1,0,1]
a =0 , b =1 , Cin =1
[S,C] =Full_adder[ 0,1,1]
a =0 , b =0 , Cin =0
[S,C] =Full_adder[ 0,0,0]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.