Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the symbol of the `mux` chip in C?

I was studying logic gates when I came to know that each logic gate was already defined in C. For example, for the AND logic gate, the symbol is &. For OR, it is |. But I could not find a symbol for the MUX chip.

So, if there is a symbol for MUX, could someone tell me? If there isn't, could someone tell me how to replicate a MUX chip in C?

like image 662
Ashish Ahuja Avatar asked Jan 17 '16 05:01

Ashish Ahuja


People also ask

What does a mux do?

A multiplexer (MUX) is a device that can receive multiple input signals and synthesize a single output signal in a recoverable manner for each input signal. It is also an integrated system that usually contains a certain number of data inputs and a single output.

What is enable line in a MUX?

An enable input makes the multiplexer operate. When EN = 0, the output is High-Z or less commonly LOW (depending on the specific device). When EN = 1, the multiplexer performs its operation depending on the selection line.

What is a 2 1 mux?

A 2-to-1 multiplexer consists of two inputs D0 and D1, one select input S and one output Y. Depending on the select signal, the output is connected to either of the inputs. Since there are two input signals, only two ways are possible to connect the inputs to the outputs, so one select is needed to do these operations.


Video Answer


3 Answers

Closest is the conditional operator: ? :

eg:

 x ? b : a 

if x is 0 you get a if it's 1 (or anything else) you get b

This operator works on entire values, like || && == and ! do. It does not operate on bits as ^ ~ & and | do.

There is no direct equivalent for a multi-input mux. but you can fake one using an anonymous array, eg:

 ((int[]){a,b,c,d,})[x]

but many people frown on constructions of that form.

if you need a bitwise mux you'll need to build it from the bitwise operators eg:

 a ^ (( b ^ a ) & x)
like image 153
Jasen Avatar answered Sep 21 '22 15:09

Jasen


Please be advised that C operates at a much higher level of abstraction than logical gates, so making such comparisons might lead to confusions. That said, the closest you might come to a demultiplexer (I'll start with that since it's simpler) is the left shift operator:

a << b

This expression, assuming that a and b are int expressions, will produce a new int whose bits are the bits of a shifted to the left b times. For example, if a is 0100011011010110 and b is 3, the result will be 0011011010110000. Now, if a is either 0 or 1 and you interpret the resulting integer as being a bus, this corresponds to a demultiplexer.

A multiplexer/selector can be implemented by the right shift operator >>, which shifts bits to the right. However, the result must be &'ed with 1 in order to clear any other bits than the one you were interested in:

(c >> b) & 1

This effectively selects the bit at index b (starting at the least significant bit) from c.

like image 23
Aasmund Eldhuset Avatar answered Sep 23 '22 15:09

Aasmund Eldhuset


C has four bitwise operators:

  • AND, &, as in a & b
  • OR, |, as in a | b
  • XOR, ^, as in a ^ b
  • NOT, ~, as in ~a

There is no MUX operator.

Be careful about your phrasing. These are called bitwise operators, and are analogous to logic gates applied to all bits in an integral type. In C logical operators are different.

like image 29
Adam Avatar answered Sep 20 '22 15:09

Adam