Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Logic Gate Functions in C Programming Subject: Computer Science - C Progra

ID: 3767162 • Letter: W

Question

Write Logic Gate Functions in C Programming

Subject: Computer Science - C Programming.

Context: This function takes in two files as inputs, one that describes the circuit and one that contains input values. The program should read the files that contain commands like INPUTVAR, OUTPUTVAR, AND, NOT, OR (And the values following the command).

Ex. INPUTVAR 3 A B C

OUTPUTVAR 1 Q

AND A B w

Which means there are 3 Input variables: A, B, C.

1 Output variable: Q

Use the AND logic and give it a variable name: w

etc. (More context below)

Explanation / Answer

You can write logic gate functions in C as given below:

------------------------------------

//NOT gate
int NOT(int A)
{
   return (!A);
}

//AND gate
int AND(int A,int B)
{
   return (A && B);
}

//OR gate
int OR(int A, int B)
{
   return (A || B);
}

//decoder
//structure for a 1-to-2 line decoder
typedef struct
{
   int D0; //D0 line.
   int D1; //D1 line
} decoder;

//creates a 1-to-2 line decoder from a given input
decoder DECODE(int A)
{
   decoder dcd;
   dcd.D0=!A; //for 1-to-2 line decoder, D0 is NOT A.
   dcd.D1=A; //for 1-to-2 line decoder, D1 is A.

   return dcd;
}

//2 input multiplexer using NAND gates. I0, I1 are input lines. A acts as a control signal
int MUX(int A, int I0, int I1)
{
   int output; //output of multiplexer
   int temp1=NOT(AND(I0,A)); //first NAND operation
   int temp2=NOT(AND(NOT(A),I1)); //second NAND operation

   output=NOT(AND(temp1,temp2)); //third NAND operation for final output

   return output;
}

-----------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote