dimanche 1 mars 2015

C function Mux.



I have this function that's a multiplexer.



// Enumerated type for a single bit.
typedef enum { FALSE=0, TRUE=1 } BIT;

BIT multi(BIT A, BIT B, BIT C, BIT D, BIT S1, BIT S0)
{
if(S1== FALSE && S0 ==FALSE)
return A;

else if(S1==FALSE && S0==TRUE)
return B;

else if (S1== TRUE && S0== FALSE)
return C;

else
return D;


}


For multiplexer, S1,S0 as a two-bit binary number, indexing into A,B,C,D, in the order given.


so like S1==0 & S0==0 refers to A and S1==0 & S0==1 refers to B etc etc.


I feel my code is close or way off or it is correct I just need to fix how I am testing it in main in which I have...



assert(multiplexer(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) == A);
assert(multiplexer(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) == D);


please and thanks in advance




Aucun commentaire:

Enregistrer un commentaire