# Thread: Logic Gates - Multiplexer Help

1. To combine gates :
Or(And(x,y), z);

or

a = and(x,y);
b = or (a,z);

Same difference.

You can call each function with whatever vars you want :

a = and(x,y);
b = and(!y,z);
c = or(a,b);

And don't be too quick to use C logical operators to do the heavy lifting for you. If you're doing anything interesting with circuit sims you'll want more than 2 possible values for signals. Think X (undefined), Hi-Z, D and D' if you're doing some sort of test pattern generation and so on.

2. You can pass the result of one function call directly into another function as a parameter. Here are some examples of calling a function:
Code:
```int a, b, c;  // inputs to your logic gate

Not(1);  // pass a literal 1 to the function -- which should return 0 (the "not" of 1)
Not(a);  // pass the value in a to the function, if a is zero, it should return 1.  For all other values it will return 0.
And(b, c);  // return the "and" of b and c.  If they are both true (non-zero), return 1, otherwise return 0.
And(a, Not(c));  // return the "and" of a and Not(c).```

3. Code:
```
#include<stdio.h>int And(int x, int y);
int Not(int x);
int Or(int x, int y);
int multiplexer(int a, int b, int c);

int main(void)
{
int a;
int b;
int c;

printf("\nEnter Value for A: ");
scanf("%i", &a);

printf("\nEnter Value for B: ");
scanf("%i", &b);

printf("\nEnter Value for C: ");
scanf("%i", &c);

printf("\n\nValue from Multiplexer = %d", multiplexer);

system("PAUSE");
return 0;
}

int Not(int x)
{
return !x;
}

int And(int x, int y)
{
return x && y;
}

int Or(int x, int y)
{
return x || y;
}

multiplexer=Or((And(a, (Not (c)))), (And(b, c)));	// Where would I put this? - And how?
// I believe this would be the correct formula```

4. Looks like the right formula. I would put that in a function, like laserlight suggested in post #8:
Code:
```int multiplexer(int a, int b, int c)
{
return Or(And(a, Not(c)), And(b, c));
}

// the line in main
printf("Value from multiplexer = %d", multiplexer(a, b, c));  // you need the (a, b, c) to actually call the function and pass it the inputs```

5. All done & working, thanks guys

6. don't think I should start another thread?
but how would I create a Xor Gate? - As i can not use the logical operators

7. There's a "long-hand" form of Xor. Write out your truth table for Xor and figure it out using the "primary" gates of Not, And & Or.