/*********************************************** * * Matthew Page * 11/05/2014 * CSCS1320 Fall 2014 * * logic_library.c - Attempting to recreate * logic library from * CSCS1240 originaly in * VBscript to C. * * ********************************************/ #include #define PREFERRED '1' #define NOTPREFERRED '0' char input; //originally created for single input in the case of nott char input1; //written for 2 inputs like every other function char input2; //written for 2 inputs like every other function char carryin; //written for 3 inputs like fullsum and fullcarry int newvalue; //returned from function value //function declarations, prototypes char nott(char); char andd(char, char); char nandd(char, char); char orr(char, char); char xorr(char, char); char halfsum(char, char); char halfcarry(char, char); char fullsum(char, char, char); char fullcarry(char, char, char); //nott function char nott(char input) { if (input == PREFERRED) { return (NOTPREFERRED); } else { return PREFERRED; } } //andd function char andd(char input1, char input2) { char result; result = NOTPREFERRED; if (input1 == PREFERRED) { if (input2 == PREFERRED) { result = PREFERRED; } } return result; } //nandd function char nandd(char input1, char input2) { char result; result = nott(andd(input1, input2)); } //orr function char orr(char input1, char input2) { char result; result = NOTPREFERRED; if (input1 == PREFERRED) { result = PREFERRED; } else { if (input2 == PREFERRED) { result = PREFERRED; } } return result; } //xorr function char xorr(char input1, char input2) { char result; result = NOTPREFERRED; if (orr(input1, input2) == PREFERRED) { if (nandd(input1, input2) == PREFERRED) { result = PREFERRED; } } return result; } //halfsum function char halfsum(char input1, char input2) { char result; result = xorr(input1, input2); return result; } //halfcarry function char halfcarry(char input1, char input2) { char result; result = andd(input1, input2); return result; } //fullsum function char fullsum(char input1, char input2, char carryin) { char result; char firstop; firstop = halfsum(input1, input2); result = xorr(firstop, carryin); return result; } //fullcarry function char fullcarry(char input1, char input2, char carryin) { char result; char firstset; char secondset; char thirdset; char firstor; firstset = andd(input1, input2); secondset = andd(input2, carryin); thirdset = andd(input1, carryin); firstor = orr(firstset, secondset); result = orr(firstor, thirdset); return result; } //calling portion of the program //(to be moved outside of this file eventually) int main() { /* printf("Enter a 1 or 0:\n"); //for 1 input scanf("%c", &input); //for 1 input newvalue = nott(input); //for 1 input */ /* printf("Enter first value, 1 or 0:\n"); //for 2 inputs scanf("%c", &input1); //for 2 inputs printf("Enter second value, 1 or 0:\n"); //for 2 inputs scanf("%c", &input2); //for 2 inputs */ /* printf("Enter 2 values (1 or 0) seperated by a space:\n"); //for 2 inputs version 2 scanf("%c %c", &input1, &input2); //for 2 inputs version 2 newvalue = halfcarry(input1, input2); //for 2 inputs function call */ printf("Enter 3 values, seperated by spaces, 2 inputs, and a carryin value (1 or 0):\n"); //for 3 inputs scanf("%c %c %c", &input1, &input2, &carryin); //for 3 inputs newvalue = fullcarry(input1, input2, carryin); //for 3 inputs printf("%c\n", newvalue); return (0); }