DEV Community

tang
tang

Posted on

Logic Gates: The Controlled Not

Tonight, my brother told me the story of a particular logic gate, the Controlled Not.

The Controlled Not is a gate that takes two inputs. If the first input is 0, the second input is unaffected, and sent as our output. If the first input is 1, we invert the second input before sending it as our output.

Pretty neat, huh? Maybe take a minute to think about how to implement it from basic logic gates (not/and/or).

I've had this spoiled for me, but here's my solution.

Previously, I've created a multiplexer. A multiplexer can be described as follows: there are three inputs, a,b, and S. S is a selector, which determines whether we output A or B. If S is 1, we output A. If S is 0, we output B.

It's represented as (A*S)+(B*~S) and looks like this:

Adapting it to our use case is pretty simple. We just need to replace A and B with A and ~A. When S is true (when our controller is on), we want to flip our A, so we'll represent that operation as (~A*S). When S is false, we want to output our A unchanged, which means that we should slot it in for what used to be our B. This looks like this: (A*~S).

All together, we get (~A*S)+(A*~S), or in plainer terms, (NOT(A) AND S) OR(A AND NOT(S)). It looks like this:

Notice anything? If not, we'll do a quick truth table.

A S | OUTPUT
-----------------
0 0 |   0
0 1 |   1
1 0 |   1
1 1 |   0
Enter fullscreen mode Exit fullscreen mode

We've got a name for this, and it's XOR.

Our takeaway is this: Even at the lowest, simplest level that we can use to try to make truth claims about the world around us- even when we've reduced everything to a collection of 1s and 0s that behave in 100% predictable ways, we're still constructing narratives around our data, still affected by the way that we choose to frame behavior, problems, solutions.

So, step back. Think about your assumptions. Think about the stories you choose to tell about your software. They matter.

Top comments (0)