More Digital Logic
Here's most of a program that adds two WORD_LENGTH binary numbers
that are given as command line arguments.
Implement the function FullAdder.
#include <iostream.h>
#include <strings.h>
const int WORD_LENGTH = 4;
typedef char Word[WORD_LENGTH+1];
void FullAdder(char Op1,char Op2,char& Carry,char& Result);
//------------------------------------------------------------------------
int main(int argc, char* argv[]) {
int Index;
char Carry;
Word Answer;
Answer[WORD_LENGTH] = '\0';
Carry = '0';
if (strlen(argv[1]) != WORD_LENGTH || strlen(argv[2]) != WORD_LENGTH) {
cout << "Words must be " << WORD_LENGTH << " bits" << endl;
return(-1);
}
for (Index=WORD_LENGTH-1;Index>=0;Index--)
FullAdder(argv[1][Index],argv[2][Index],Carry,Answer[Index]);
cout << Carry << " " << Answer << endl;
return(0);
}
//------------------------------------------------------------------------