{"id":260384,"date":"2021-05-27T15:00:00","date_gmt":"2021-05-27T12:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/"},"modified":"2021-05-27T15:00:00","modified_gmt":"2021-05-27T12:00:00","slug":"how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/","title":{"rendered":"#How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, and NOT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a3dcce54facd\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a3dcce54facd\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#What_Is_a_Logic_Gate\" >What Is a Logic Gate?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#OR\" >OR<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#AND\" >AND<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#XOR\" >XOR<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#NOR\" >NOR<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#NAND\" >NAND<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#XNOR\" >XNOR<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#NOT\" >NOT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#Logic_Gates_in_Computer_Code\" >Logic Gates in Computer Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/buradabiliyorum.com\/en\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/#Wrapping_up\" >Wrapping up<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, and NOT&#8221;<\/strong><\/p>\n<figure id=\"attachment_11512\" style=\"width: 1964px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage wp-image-11512 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/22e2d43d.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"logic gate symbols\" width=\"1964\" height=\"892\" \/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-vector\/digital-logic-gate-symbols-white-isolated-518568409\">Shutterstock\/darsi<\/a><\/span><\/figcaption><\/figure>\n<p>Logic gate: a cool term, but what does it mean? This article will introduce the concept of a logic gate as well as describe how each specific logic gate (OR, AND, XOR, NOR, NAND, XNOR, and NOT) works.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_a_Logic_Gate\"><\/span>What Is a <i>Logic Gate<\/i>?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>First, it&#8217;s important to realize that logic gates take many forms. Even in our personal lives, we are constantly processing things through various logic gates. While our minds are optimized at doing so, we often do not realize the thought process in motion. However, it does take place.<\/p>\n<p>For example, when sitting an exam, one might know that not answering a question will lead to a negative score for that question. If you thought this through and understood the concept, your mind has just processed a <code>NOT<\/code> gate! In other words (pseudo code): <code>if <strong>NOT<\/strong> {question answered} THEN negative consequences exist<\/code>.<\/p>\n<p>Such logic gates form the building blocks for much of the world&#8217;s code as well as for electronics. While some logic gates are much more common (for example, an\u00a0<code>AND<\/code> or <code>OR<\/code> gate is much more common than a <code>NAND<\/code> or <code>NOR<\/code> gate), all logic gates are sooner or later used to get a computer or electronic device to do exactly what&#8217;s required of it&#8212;to process data in a certain way.<\/p>\n<p>With the help of multiple logic gates, we can construct workflows that to some extent resemble or follow human thinking. Let&#8217;s look at each one in detail.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"OR\"><\/span>OR<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>An <code>OR<\/code> logic gate is a very simple gate\/construct that basically says, &#8220;<em>I<\/em><i>f my first input is true, or my second input is true, or both are true, then the outcome is true also<\/i>.&#8221; Note how we have two inputs and one output. This isn&#8217;t the case for all logic gates. If you take a look at the header image, you can see how all logic gates have two inputs&#8212;except for the <code>NOT<\/code> logic gate, which has one input. All gates have one output.<\/p>\n<p>In other words, we can write an <code>OR<\/code> logic gate into this flowchart:<\/p>\n<pre>0 + 0 =&gt; 0\n0 + 1 =&gt; 1\n1 + 0 =&gt; 1\n1 + 1 =&gt; 1\n<\/pre>\n<p>Here,\u00a0<code>0<\/code> represents <code>false<\/code> and <code>1<\/code> represents <code>true<\/code>. As you can see, the only way that our output could ever be <code>false<\/code> (i.e. <code>0<\/code>) is if both inputs were also\u00a0<code>false<\/code>. In all other cases, the output of our <code>OR<\/code> gate will be <code>true<\/code>.<\/p>\n<p>Interestingly, if both inputs are <code>true<\/code>, the output will also be <code>true<\/code>. This is a little offset from a human thinking about <code>OR<\/code>, as the word <i>or<\/i> is often associated with one or the other.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"AND\"><\/span>AND<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Similar to our <code>OR<\/code> logic gate, the <code>AND<\/code> logic gate will process two inputs resulting in one output, but this time, we&#8217;re looking for both inputs to be <code>true<\/code> for the outcome to become <code>true<\/code>. In other words, our logic works like this:<\/p>\n<pre>0 + 0 =&gt; 0\n0 + 1 =&gt; 0\n1 + 0 =&gt; 0\n1 + 1 =&gt; 1\n<\/pre>\n<p>All other gates (except for the <code>NOT<\/code> gate) are a little more tricky to comprehend, but stay tuned.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"XOR\"><\/span>XOR<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>XOR<\/code> gate is also sometimes called <code>EOR<\/code> or <code>EXOR<\/code>. The correct lingo for an <code>XOR<\/code> gate is <i>Exclusive OR<\/i>. If you remember our previous example, we were a little surprised that <code>true<\/code> and <code>true<\/code> would still lead to <code>true<\/code>, somewhat unlike human reasoning.<\/p>\n<p>Welcome to <code>XOR<\/code> (<strong>exclusive<\/strong> OR), which solves this problem, much in line with standard human reasoning. This logic gate works like this:<\/p>\n<pre>0 + 0 =&gt; 0\n0 + 1 =&gt; 1\n1 + 0 =&gt; 1\n1 + 1 =&gt; 0\n<\/pre>\n<p>The input and output are the same as our <code>OR<\/code> gate, but this time, the input really does need to be <i>exclusive<\/i>. If the input is <code>true<\/code> and <code>true<\/code>, the output is <code>false<\/code>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"NOR\"><\/span>NOR<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Remember our earlier <code>NOT<\/code> example? We&#8217;ve reversed things. It&#8217;s somewhat similar to the <code>NOR<\/code> gate, which is basically a <code>NOT-OR<\/code> gate where <code>OR<\/code> is of the same logic as we discussed above for the <code>OR<\/code> gate.<\/p>\n<p>In other words, you might think about it like this: &#8220;<em>A<\/em><i>nything which is not an OR-situation (i.e. <code>true<\/code> and <code>false<\/code> mixed or <code>true<\/code> and <code>true<\/code> alike to our <code>OR<\/code> gate example, even if not im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely logical to humans) renders a <code>true<\/code> outcome, and all the rest results in a <code>false<\/code> outcome.<\/i>&#8221;<\/p>\n<p>This leads to the following <code>NOR<\/code> gate logic:<\/p>\n<pre>0 + 0 =&gt; 1\n0 + 1 =&gt; 0\n1 + 0 =&gt; 0\n1 + 1 =&gt; 0\n<\/pre>\n<p>Armed with this knowledge, we can take a look at the <code>NAND<\/code> gate:<\/p>\n<h2><span class=\"ez-toc-section\" id=\"NAND\"><\/span>NAND<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Akin to <code>NOR<\/code>,\u00a0<code>NAND<\/code> could be read as <code>NOT-AND<\/code>, and thus, anything that&#8217;s normally an <code>AND<\/code> has to be false (i.e. <code>NOT-AND<\/code>). This leads to the following outcome:<\/p>\n<pre>0 + 0 =&gt; 1\n0 + 1 =&gt; 1\n1 + 0 =&gt; 1\n1 + 1 =&gt; 0\n<\/pre>\n<p>As in each of the first three cases, a full <code>AND<\/code> (which would be <code>true<\/code> and <code>true<\/code>) isn&#8217;t present. Hence, the outcome is <code>true<\/code> (<code>1<\/code>). For the last input, <code>true<\/code> and <code>true<\/code>, a full <code>AND<\/code> is present and thus (due to the <code>NOT<\/code> component, the <code>N<\/code> in <code>NAND<\/code>), the outcome is false.<\/p>\n<figure id=\"attachment_11513\" style=\"width: 434px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-11513 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/a410c0eb.jpg?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Texas Instruments chip\" width=\"434\" height=\"536\" \/><figcaption class=\"wp-caption-text\"><span class=\"imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/commons.wikimedia.org\/wiki\/File:TexasInstruments_7400_chip,_view_and_element_placement.jpg\">Audrius Meskauskas, CC BY-SA 3.0, via Wikimedia Commons<\/a><\/span><\/figcaption><\/figure>\n<p>In this image, we see an SN7400N chip that has four logic gates, namely,\u00a0<code>NAND<\/code> gates. Thus, a higher voltage (a <code>true<\/code>\/<code>1<\/code> state) on pins 1 and 2 (bottom left) will lead to a low voltage (likely 0V) state on pin 3 at any given time. And if one of the two or both pins (1+2) would become low voltage, pin 3 would start providing a higher voltage.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"XNOR\"><\/span>XNOR<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Thinking back on the <code>OR<\/code>, <code>NOR<\/code>, and <code>XOR<\/code> gates, the <code>XNOR<\/code> gate is a combination of all of them. Basically, an <i>Exclusive NOT-OR<\/i> or <code>Exclusive NOR<\/code> gate. The logic is as follows:<\/p>\n<pre>0 + 0 =&gt; 1\n0 + 1 =&gt; 0\n1 + 0 =&gt; 0\n1 + 1 =&gt; 1\n<\/pre>\n<p>In other words, the reverse of a\u00a0<code>XOR<\/code> gate outcome. Yes, it can get a little complex to follow.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"NOT\"><\/span>NOT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We already briefly introduced the <code>NOT<\/code> gate earlier with our human equivalent example. The <code>NOT<\/code> gate basically reverses whatever input is given to it. If you provide <code>true<\/code> as the input, the output will be <code>false<\/code> and vice versa. Our logic table is simple:<\/p>\n<pre>0 =&gt; 1\n1 =&gt; 0\n<\/pre>\n<p>This gate is often used in combination with other gates.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Logic_Gates_in_Computer_Code\"><\/span>Logic Gates in Computer Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A simple example of a <code>NOT<\/code> gate can be seen in the following Bash code:<\/p>\n<pre>if [ ! true ]; then echo 'false'; else echo 'true'; fi\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-11148 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/7b6fbd4c.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A NOT logic gate in use in Bash code\" width=\"530\" height=\"54\" \/><\/p>\n<p>In this example, we basically say:\u00a0<code>if not true, then echo false, otherwise echo true<\/code>. Because we use a <code>NOT<\/code> gate, the output is true even though <code>not true<\/code> is false.<\/p>\n<p>As you can see, code easily gets a little confusing to read and develop when you use <code>NOT<\/code> gates, and especially so when combining them with <code>AND<\/code> or <code>OR<\/code> gates. But practice makes perfect, and seasoned developers love to use complex gate conditional statements.<\/p>\n<p>In many coding languages, a logical <code>OR<\/code> gate is represented by the <code>||<\/code> idiom, and an\u00a0<code>AND<\/code> logic gate is often represented by the <code>&amp;&amp;<\/code> idiom. A <code>NOT<\/code> gate is usually represented by the <code>!<\/code> symbol.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Wrapping_up\"><\/span>Wrapping up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this article, we discussed the OR, AND, XOR, NOR, NAND, XNOR, and NOT logic gates. We also covered how logic gates mimic human thinking and how they can help us write complex pieces of programming logic in a computer program. We also had a brief look at logic gates as used in computer code.<\/p>\n<p>If you enjoyed reading this article, take a look at our From 0 to F: Hexadecimal and Bits, Bytes, and Binary articles, which will help you understand how computers work internally.<\/p>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/11147\/how-logic-gates-work-or-and-xor-nor-nand-xnor-and-not\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How Logic Gates Work: OR, AND, XOR, NOR, NAND, XNOR, and NOT&#8221; Shutterstock\/darsi Logic gate: a cool term, but what does it mean? This article will introduce the concept of a logic gate as well as describe how each specific logic gate (OR, AND, XOR, NOR, NAND, XNOR, and NOT) works. What Is a Logic&#8230;<\/p>\n","protected":false},"author":1,"featured_media":260385,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/05\/22e2d43d.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-260384","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/260384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=260384"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/260384\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/260385"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=260384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=260384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=260384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}