MATLAB Answers


how to create function half adder in matlab

Asked by manaf nehad on 2 Apr 2018
Latest activity Answered by Roger Stafford on 2 Apr 2018
halfAdder : it accepts 2 bits as input arguments. It adds these bits and returns 2 bits as output arguments: the sum and the output carry

  1 Comment

What is this for? How are the bits passed in? I.e., what are the variable classes involved?

Sign in to comment.


1 Answer

Answer by Roger Stafford on 2 Apr 2018
 Accepted Answer

If the input bits are numeric scalars or logical values, b1 and b2, then the sum bit, 's', would be:
s = b1 xor b2;
or else
s = (b1&~b2) | (~b1&b2);
These are equivalent. That leaves you with the 'carry' bit to figure out.


Sign in to comment.