Four bit adder: Difference between revisions

Content added Content deleted
(→‎{{header|C}}: xor operator will work correctly on two one-bit operands)
(use of xor operator was forbidden for this task -- Undo revision 84068 by 169.232.246.15 (Talk))
Line 29: Line 29:


#define NOT(X) (~(X)&0x01)
#define NOT(X) (~(X)&0x01)
#define XOR(X,Y) ((NOT(X)&(Y)) | ((X)&NOT(Y)))


void halfadder(IN a, IN b, OUT s, OUT c)
void halfadder(IN a, IN b, OUT s, OUT c)
{
{
V(s) = V(a) ^ V(b);
V(s) = XOR(V(a), V(b));
V(c) = V(a) & V(b);
V(c) = V(a) & V(b);
}
}