Logic Gates - Multiplexer Help

This is a discussion on Logic Gates - Multiplexer Help within the C Programming forums, part of the General Programming Boards category; To combine gates : Or(And(x,y), z); or a = and(x,y); b = or (a,z); Same difference. You can call each ...

  1. #16
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    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. #17
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,629
    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. #18
    Registered User
    Join Date
    Dec 2011
    Posts
    12
    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. #19
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,629
    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. #20
    Registered User
    Join Date
    Dec 2011
    Posts
    12
    All done & working, thanks guys

  6. #21
    Registered User
    Join Date
    Dec 2011
    Posts
    12
    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. #22
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,629
    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.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program related to logic gates!
    By yellowmania in forum C Programming
    Replies: 4
    Last Post: 02-14-2012, 07:38 AM
  2. Are you the next Gates?
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 08-04-2008, 07:59 PM
  3. Bill Gates!
    By Sentral in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 06-21-2006, 01:22 AM
  4. a multiplexer/data selector question
    By axon in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-12-2003, 03:48 PM
  5. Logic Gates
    By JFK in forum C Programming
    Replies: 0
    Last Post: 10-21-2001, 06:56 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21